• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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.
 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic