The Artima Developer Community
Sponsored Link

Java Answers Forum
simple array problem

4 replies on 1 page. Most recent reply: Mar 17, 2003 3:55 AM by Timsy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Nilkanth

Posts: 4
Nickname: nilkanth
Registered: Mar, 2003

simple array problem Posted: Mar 16, 2003 10:38 AM
Reply to this message Reply
Advertisement
Hi,
I've tokenize some lines and got some tokens. Now I wanna store those tokens in an array. Can someone help? Thanks.


Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: simple array problem Posted: Mar 16, 2003 12:56 PM
Reply to this message Reply
1. When you create tokenizer then get the total number of tokens.
2. Create an array of that size. You got size in step 1.
3. As you iterate using tokenizer keep storing the elements in your array.

Nilkanth

Posts: 4
Nickname: nilkanth
Registered: Mar, 2003

Re: simple array problem Posted: Mar 16, 2003 3:00 PM
Reply to this message Reply
Hi Kishori,
Thanx for ur reply. Now I've store the tokens in the array. The tokens r something like:
hello this stay here come this go there 34 32.
Now I wanna find out if the token==this, then get the position of the before element, ie for 'hello' and 'come'. And if the token==this then convert the tokens following it in it's char value until next 'this' is hit. I tried something like:
if(allTheStrings[x].equals("this"))
System.out.println(allTheStrings[x-1]);
But this doesn't work. Can u pls advise? Thanks.

Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: simple array problem Posted: Mar 16, 2003 8:51 PM
Reply to this message Reply
Hi
The output of the program is not clear to me. Please describe the problem in details and also include the inputs and desired outputs of the program. I will try to solve it.

Thanks
Kishori

Timsy

Posts: 3
Nickname: timsy
Registered: Mar, 2003

Re: simple array problem Posted: Mar 17, 2003 3:55 AM
Reply to this message Reply
public static void search1(String str){
StringTokenizer strTok = new StringTokenizer(str);
String temp;
int i = strTok.countTokens();
String strArr[] = new String;

for( i=0; strTok.hasMoreTokens(); i++){
strArr = strTok.nextToken();
}

for(i=0; i < strArr.length ; i++)
{
if (strArr.equals("this"))
{
System.out.println(strArr[i-1]);
}
}
}

Flat View: This topic has 4 replies on 1 page
Topic: banking system-please help! Previous Topic   Next Topic Topic: trying to update this applet

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use