• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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: 24204
44
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."
 
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic