String array split.

Hi,

I'm having some problems with this code, but I can't figure out how to do this.

-this what I know about the method

-the split method is used to organize an array:

-the output is suppose to look something like this:

cat

bat

mouse

moose

but unfortunately for me, its not working even compiling. This code is an example my instructor gave me, but I don't understand why its not working.

String[] animals ="cat, bat, mouse, moose".split(",");

[564 byte] By [vopoa] at [2007-11-27 10:08:26]
# 1
What is the actual compiler error saying?
cotton.ma at 2007-7-13 0:44:55 > top of Java-index,Java Essentials,Java Programming...
# 2
I made some changes to the code and it works now, but I get this output:-I don't know what it meanssplit: [Ljava.lang.String;@3e25a5
vopoa at 2007-7-13 0:44:55 > top of Java-index,Java Essentials,Java Programming...
# 3
It means you did thisSystem.out.println(animals);
cotton.ma at 2007-7-13 0:44:55 > top of Java-index,Java Essentials,Java Programming...
# 4

String[] animals = "cat, bat, mouse, moose".split(",");

it will be better for you if you put the string like this.

String line = "cat, bat, mouse, moose";

then

String [] animals = line.split(",");

for(int i=0; i<animals.length; i++)

{

System.out.println(animals[i]);

}

>

bail_wa at 2007-7-13 0:44:55 > top of Java-index,Java Essentials,Java Programming...
# 5
> String[] animals = "cat, bat, mouse,> moose".split(",");> > > it will be better for you if you put the string like> this.Why?
cotton.ma at 2007-7-13 0:44:55 > top of Java-index,Java Essentials,Java Programming...
# 6
personal preferences and more clean to me.
bail_wa at 2007-7-13 0:44:55 > top of Java-index,Java Essentials,Java Programming...
# 7
thanks
vopoa at 2007-7-13 0:44:55 > top of Java-index,Java Essentials,Java Programming...
# 8
0.02cBeware the spaces.
floundera at 2007-7-13 0:44:55 > top of Java-index,Java Essentials,Java Programming...