Solved

java

Posted on 2003-12-10
5
250 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
Comment Utility
what language?
0
 
LVL 15

Accepted Solution

by:
jimmack earned 20 total points
Comment Utility
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
Comment Utility
Exactly what would have been required for a grade A?
0
 

Author Comment

by:sandipmurmu
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
A short article about a problem I had getting the GPS LocationListener working.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

763 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

9 Experts available now in Live!

Get 1:1 Help Now