• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get all tokens of StringTokenizer into a ArrayList?  RSS feed

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, this doesn't belong in "Advanced." I'll move it to "Intermediate."
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!