Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

StringTokenizer

Lets  StringTokenizer fields = new StringTokenizer("one|two|three", "|");
How can i refer to the first item in fields.  I know fields.nextToken( ) will give any element.
Exple using an array i will say fields[0] ===> one, How do i do it with  StringTokenizer?

Thanks.
0
komlaaa
Asked:
komlaaa
  • 3
1 Solution
 
objectsCommented:
fields.nextToken();
0
 
objectsCommented:
if you want to get an array you can use split() instead of StringTokenizer

String[] fields = "one|tow|three".split("\\|");
0
 
objectsCommented:
or you can even create an array using StringTokenizer

StringTokenizer fields = new StringTokenizer("one|two|three", "|");
String[] array = { fields.nextToken(), fields.nextToken(), fields.nextToken() };
0
 
komlaaaAuthor Commented:
Thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now