Solved

java

Posted on 2003-12-10
5
261 Views
Last Modified: 2010-04-17
how shall i extract words from a given string and store the words in an array?

sandip.
0
Comment
Question by:sandipmurmu
  • 3
5 Comments
 
LVL 9

Expert Comment

by:malharone
ID: 9914662
what language?
0
 
LVL 15

Accepted Solution

by:
jimmack earned 20 total points
ID: 9916853
malharone: did you read the question title before you opened it? ;-)

sandipmurmu:

import java.util.*;

public class Splitter
{
    public static void main(String[] args)
    {
        String myString = "This is a sentence";
        StringTokenizer st = new StringTokenizer(myString);
        String[] array = new String[st.countTokens()];
        int i = 0;
        while (st.hasMoreTokens())
        {
            array[i] = st.nextToken();
            i++;
        }
       
        for (int j = 0; j < array.length; j++)
        {
            System.out.println(array[j]);
        }
    }
}
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9919080
Exactly what would have been required for a grade A?
0
 

Author Comment

by:sandipmurmu
ID: 9919348
dear jimmack,
I appreciate your answer to my question and is indeed good.
however it throws an Exception
"ArrayIndexOfBoundsExecption"..

However ,Sincerely, it deserves u Grade A.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9919368
Do you need further help to clear up the exception?

Where is this occurring (I tested the code and it worked OK).
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.

749 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