fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13.  
  14. ArrayList<Test> rutaList = new ArrayList<>();
  15.  
  16. String[] testa = {"hola", "test", "aqui"};
  17.  
  18. String nombre;
  19.  
  20.  
  21. for ( int i = 0; i < 3; i++) {
  22.  
  23. Test map = new Test();
  24.  
  25. nombre = testa[i];
  26.  
  27. System.out.println(i);
  28. System.out.println(nombre);
  29.  
  30. map.setNombre((String) nombre);
  31.  
  32. rutaList.add(map);
  33. }
  34.  
  35.  
  36. //miramos rutaList
  37. System.out.println("---");
  38.  
  39. for(int a = 0; a < rutaList.size(); a++){
  40. System.out.println(rutaList.get(a).getNombre());
  41. }
  42. }
  43. }
  44.  
  45. class Test{
  46.  
  47. String nombre;
  48.  
  49. public void setNombre(String n){
  50. this.nombre = n;
  51. }
  52.  
  53. public String getNombre(){
  54. return this.nombre;
  55. }
  56. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
0
hola
1
test
2
aqui
---
hola
test
aqui