• 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

how to get all tokens of StringTokenizer into a ArrayList?

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
StringTokenizer st=new StringTokenizer(Sup_Email1, ",");
ArrayList list1 = new ArrayList();
System.out.println("the tokens got here in while are:"+st.countTokens());

for(i=0;i<=size;i++){System.out.println("inside for");
while(st.hasMoreTokens()){System.out.println("inside while");
list1.add(st.nextToken());
}//end of while
}//end of for


for(Iterator iter=list1.iterator(); iter.hasNext() {
System.out.println((String)(iter.next())); //---------gives me only 1st token
}
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shivan

I don't think this question belongs to "advanced" forum.

Anyways, your loops seem non-logical to me. It should be,



Isn't it that simple? How come you ended up using two loops?

Thanks
Maulin
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, this doesn't belong in "Advanced." I'll move it to "Intermediate."
reply
    Bookmark Topic Watch Topic
  • New Topic