I'm trying to convert a string into an array of tokens, and while I've been finding questions similar to this all over the internet, no one is explaining how to specifically convert the words into a string. For example, I might do this:
String a = "I am a unicorn.";
String b[] = a.split(" ", -1);
for (int i = 0; i < b.length; i++)
System.out.println(b);
When I run this, however, it prints this:
[Ljava.lang.String;@15db9742
[Ljava.lang.String;@15db9742
[Ljava.lang.String;@15db9742
[Ljava.lang.String;@15db9742
I'm finding, all over the internet, this exact same code, yet I'm not finding anyone explaining how to fill the array with the tokens that I specified in my string.
(Also, please don't virtually "yell" at me for my variables! :) A lot of times when I ask questions about Java, people prefer to respond with things like, "a and b aren't proper variables, you should use more specific words", rather than answering my question. But keep in mind, this is just an example, so you guys can get an idea of what I'm talking about - I use all of the proper rules of coding in every other situation.)
Every time you are trying to print the whole array
try.
for (int i = 0; i < b.length; i++)
System.out.println(b[i]);
or even use a for-each loop
for (String el : b) {
System.out.println (el);
}
ALSO CHANGE YOUR VARIABLE NAMES TO SOMETHING MORE MEANINGFUL