Solved

java

Posted on 2003-12-10
5
258 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

A short article about problems I had with the new location API and permissions in Marshmallow
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

776 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