Solved

java

Posted on 2003-12-10
5
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

This is an explanation of a simple data model to help parse a JSON feed
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.
Six Sigma Control Plans
Starting up a Project

688 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