Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

help on output +=  RSS feed

 
catherine matthews
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i get the words stored in the form of Output += load[s]; and use it in another method?? i cannot declare the load[] as global as uyou can see below.... Please help me... I want to get each of the words...as an array not as a single string..


// getting the words from the lines, make into an array of words

public String getwords(){
StringTokenizer words = new StringTokenizer(output);
numtoken = words.countTokens();
String load[] = new String [numtoken];
int s = -1;
while (words.hasMoreTokens())
{
load[++s]= words.nextToken();

arrwords += load[s] ;
}

return arrwords;
}






public String theMethods()
{
// here i need to find the occrances of { and } and find their index
}
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not :


[ May 30, 2006: Message edited by: Garrett Rowe ]
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using Java 1.5, is can be done even easier using String.split()

 
catherine matthews
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okie..... once i have the
public String [] getwords()
{
return load
}

and i call the method like this??

public String theMethods()
{
for(i = 0; i < getwords().length; i++)
{
// how do i get the elements inside the array load??? the Strings??? like this??
but i cant do it.... anyway
if(getwords().indexOf("{") > -1)

and i cannot initialize the array load as a global because it has to be dynamic...and gets the length and elements once it goes through the method
getmethod()....
[ May 30, 2006: Message edited by: catherine matthews ]
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by catherine matthews:
okie..... once i have the
public String [] getwords()
{
return load
}

and i call the method like this??

public String theMethods()
{
for(i = 0; i < getwords().length; i++)
{
// how do i get the elements inside the array load??? the Strings??? like this??
but i cant do it.... anyway
if(getwords().indexOf("{") > -1)

and i cannot initialize the array load as a global because it has to be dynamic...and gets the length and elements once it goes through the method
getmethod()....

[ May 30, 2006: Message edited by: catherine matthews ]


You can assign it to a local variable. However remember arrays don't have an indexOf() method, however you can create one yourself:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!