• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Batches of array in an ArrayList

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to save a batches of array references in an ArrayList:

Printing it, only the first Array saved in a ArrayList has values, the rest prints null. From the code, i tried to save the references of array object "names" to an array list. If i re-initialize the variable, what will happen to the referrence that was previously saved in an ArrayList?

Hope i made my question clear. Thanks!

[ June 11, 2004: Message edited by: john von ]
[ June 11, 2004: Message edited by: john von ]
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are trying to add an array of strings in a list...
Why you re making your life difficult?

Try this:

ArrayList a=new ArrayList();

for(int i=0;i<names.length;i++)
{
a.add(names[i].concat(new Integer(i).parseInt(i)));
}


If you wanna print your list try:

System.out.println(a); // You get the hole list
or try:

for (int i=0;i<a.size();i++)
System.out.println(a.get(i));


This code is written on the fly, and not compiled, and maybe has a bug.But i think it is working.The philosophy is right.

Farewell.
 
reply
    Bookmark Topic Watch Topic
  • New Topic