473,326 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

token separation in array

83
I want to split the String using array. i am do it on the simple method.

But i want change the below code by using array.

class example1
{
public static void main(String arg[]) {

StringTokenizer st = new StringTokenizer("this is a test");
while (st.hasMoreTokens()) {
String key=st.nextToken();
System.out.println(key);
}
}
}
the out put is like this

this
is
a
test

so pls do the needful

Thanks
Sang
Sep 23 '06 #1
3 6648
r035198x
13,262 8TB
I want to split the String using array. i am do it on the simple method.

But i want change the below code by using array.

class example1
{
public static void main(String arg[]) {

StringTokenizer st = new StringTokenizer("this is a test");
while (st.hasMoreTokens()) {
String key=st.nextToken();
System.out.println(key);
}
}
}
the out put is like this

this
is
a
test

so pls do the needful

Thanks
Sang
Unfortunately you are not being very clear on what you want to do.
The following might help:

To convert a string to an array of characters, do string.toCharArray();

The best string splitter method is string.split(regexp); http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html#sum


The StringTokenizer should now be avoided. It is now one of those older classes which sun may soon deprecate.
Sep 23 '06 #2
Hi, you forgote the second StringTokenizer parameter.

import java.util.StringTokenizer;

public class TokenizerTest {
public static void main(String[] args) {

StringTokenizer st = new StringTokenizer("this is a test"," ");
while (st.hasMoreTokens()) {
String key=st.nextToken();
System.out.println(key);
}
}
}
Sep 24 '06 #3
abadi
5
I hop this is what you want

class Test {
public static void main(String[] args) {
ArrayList tokensArray = new ArrayList();
StringTokenizer st = new StringTokenizer("this is a test");
while (st.hasMoreTokens()) {
tokensArray.add(st.nextToken());
}
}
}
Sep 25 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Steve | last post by:
I'm writing a snippet of code intended to parse a grid that is represented by a long string. Each row of the grid is deliminated in the string with a '~' character. Inside each row substring,...
20
by: Griff | last post by:
Hi there I'm after some suggestions as to how one might best separate form and content in a normal run-of-the-mill web application. I'm sure whole bookshelves have been written on this, but I...
0
by: Marc van Boven | last post by:
I'm stuck with the following problem: My nusoap-client calls a server-function giveCombination(). The function giveCombination should return something like array( => array( 'a_id' => 6,...
1
by: G Fernandes | last post by:
Hi, can someone tell me what the following words mean as per C/clc: 1) token 2) token sequence 3) scalar variable 4) vector
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
9
by: Nelmr1 | last post by:
I'm using 2002.Net, 1.0 framwork. I am basically learning C# so I wrote this and get invalid token errors. Does anyone see why? using System; namespace ConsoleApplication2 {
10
by: Frank van Wensveen | last post by:
Friend, coders, fellow wage slaves, lend my your ears. I believe that in a perfect world the design of a website (or feature on a website) should be totally separated from its design and the data...
3
by: cherryst152 | last post by:
Ok, so i have a php random number generator that creates two unique numbers between 1 and 10, what i want to add that i can't figure out for the life of me is how to implement that these two numbers...
1
by: Someone21 | last post by:
Hi all, I am currently trying to retrieve a string from a textfile, separate that and put it in an array. I stumbled on the problem that *token is a pointer, and not the string. However when i...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.