message like string[] args from main() methods

String message;

while ((message = in.readUTF()) != null) {
//String[] array = message; -- gives error incompatible types

System.out.print("* Message from peer: " + message + "\n");
}

How can I split the message so i could use like

if (message[0].equals("hi")) ..
else if (message[2].equals("hey")) ..
[366 byte] By [pouncer] at [2007-11-20 11:53:29]
# 1 Re: message like string[] args from main() methods
I don't understand your question. Does message contain a number of words that you want to split into an array of words? If so (and the words are separated by a space character) you can do that using the split method eg:String[] words = message.split(" ");
keang at 2007-11-10 2:13:59 >
# 2 Re: message like string[] args from main() methods
StringTokenizer st = new StringTokenizer(yourString," ");
//where second string parameter is your devider criteria
while(st.hasMoreTokens()){
System.out.println(st.nextToken());
}
this example will devide yourString to pieces jumping over each " " symbol. Beware that if u have 2 spaces together (" ") in yourString for ex. st.nextToken() will consider them as 2 separate spaces, and since we've put 1 space as a divider criteria it will give u an empty string between the spaces as a token.

Id recommend eliminating all more-than-one spaces between words in your string (dont forget to trim it) and only then apply the tokenizer.
Xeel at 2007-11-10 2:14:59 >
# 3 Re: message like string[] args from main() methods
Sun have recommended that String.split(..) or Scanner should be used in preference to StringTokenizer. It hasn't been deprecated, but it is effectively superceded.

A language that doesn't affect the way you think about programming is not worth knowing...
A. Perlis
dlorde at 2007-11-10 2:15:55 >