fork(1) 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. Test map = new Test();
  16. String[] testa = {"hola", "test", "aqui"};
  17.  
  18. String nombre;
  19.  
  20.  
  21. for ( int i = 0; i < 3; i++) {
  22.  
  23. nombre = testa[i];
  24.  
  25. System.out.println(i);
  26. System.out.println(nombre);
  27.  
  28. map.setNombre((String) nombre);
  29.  
  30. rutaList.add(map);
  31. }
  32.  
  33.  
  34. //miramos rutaList
  35. System.out.println("---");
  36.  
  37. for(int a = 0; a < rutaList.size(); a++){
  38. System.out.println(rutaList.get(a).getNombre());
  39. }
  40. }
  41. }
  42.  
  43. class Test{
  44.  
  45. String nombre;
  46.  
  47. public void setNombre(String n){
  48. this.nombre = n;
  49. }
  50.  
  51. public String getNombre(){
  52. return this.nombre;
  53. }
  54. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
0
hola
1
test
2
aqui
---
aqui
aqui
aqui