[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

java

Posted on 2003-12-10
5
Medium Priority
?
267 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 60 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Progress
Introduction to Processes

650 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