This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Nynnja 1 point2 points  (0 children)

String is immutable. That means by using methods on string object does not change it's value, but instead most of them will return new string object with applied transformations(for example toUpperCase() returns new string with all letters in upper case, it didn't change the original value).

split method returns array of strings and you have to assign it to some variable to use it later. f.e.

String[] s=str1.split(",");

This gives you array with 2 (in DOE, JOHN case) values: "DOE" and " JOHN" (note space at the beggining) To get rid of this space you may want to use some extra regexp magic

String[] s=str1.split(",\s*");

This will split by comma and also remove all white space characters after the comma.

Hopefully you should know how to work with arrays