Posted on 2004-11-02
Last Modified: 2010-03-31
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?

Question by:komlaaa
    LVL 92

    Expert Comment

    LVL 92

    Accepted Solution

    if you want to get an array you can use split() instead of StringTokenizer

    String[] fields = "one|tow|three".split("\\|");
    LVL 92

    Expert Comment

    or you can even create an array using StringTokenizer

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

    Author Comment


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    factory design pattern vs abstract factoy design pattern 2 63
    wordsWithoutList  challenge 24 61
    IT Company 5 56
    wordlen challenge 3 29
    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now