I am a newbie to java and I am trying to begin with a simple task- list a group of names into alphabetical order. Currently, my code is fine:
import java.util.Arrays;
public class CLASSROOM_SSONG {
String[] names = {"Joe", "Bob", "Andy"};
public static void main(String args[]) {
CLASSROOM_SSONG x =new CLASSROOM_SSONG();
x.roster();
}
public String [] roster() {
Arrays.sort(names);
System.out.println(Arrays.toString(names));
return names;
}
}
However, this code returns an ARRAY with the brackets, and I prefer there to be names on separate lines without the brackets. This is what I am looking for it to return:
Andy
Bob
Joe
How would I do that? I thought 'println' would give each a separate line, but now I am stuck. I can't think of a way without having to print each name separately, which defeats the purpose completely.
All help would be appreciated!
Oh, by the way, when I search for answers, sometimes I get crazy things with a ton of helper methods. I Prefer simple ones that I can read :)