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

string manipulation

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a string like this: aaa,bbb,cccc

i want to extract out to be like,
aaa, 1st element
bbb, 2nd element
ccc, 3rd element

of a vector. How should i do it?
 
Ranch Hand
Posts: 1252
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



According to me, I Hope it helps you...

If any concern still then revert me back.


[ July 11, 2006: Message edited by: Ankur Sharma ]
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.util.Vector vec = new java.util.Vector(java.util.Arrays.asList("aaa,bbb,cccc".split(",")));
 
Shaan Shar
Ranch Hand
Posts: 1252
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Dunn:
java.util.Vector vec = new java.util.Vector(java.util.Arrays.asList("aaa,bbb,cccc".split(",")));



Oops...

I wish I would like to give this solution...

Thanks Michael Dunn

Very smart solution...
 
fang eve
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now i understand how split() is being used. I have another problem here. for example my string is aaa,bbb,ccc,aaa.
i want to take out all the elements, but i do not want to have repetition of element.

i want it to be:
aaa
bbb
ccc

the element aaa, only appear once.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use a Set.
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
StringTokenizer is only around for legacy issues, and should never be used in new code.
 
fang eve
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what you mean? i dont get you, do you have sample codes? How to use a Set?
[ July 11, 2006: Message edited by: fang eve ]
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A Set is an interface that doesn't allow duplicates.

It is part of the Collections API.

If you look in the API at HashSet, you will see an example of a Set.
 
fang eve
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh ok, thanks

Another question here, i have the string like," a.content", "contents".

i have done a function to remove anything before the full-stop. but however, if i pass in the 2nd string ("contents"), it throws me an error.
How i check the string whether if it contain full-stop?
[ July 11, 2006: Message edited by: fang eve ]
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

have a look at the indexOf function
 
I am mighty! And this is a mighty small ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic