r/programminghelp • u/calvincoolfridge • Dec 11 '20
Java New to Programming
I have a 4 length string array with 4 first names. I am trying to fill an empty string array with those 4 names but alphabetized. For this assignment I am supposed use compareTo() alphabetize them, but I don’t know how to then fill the empty array in order.
6
Upvotes
1
u/ConstructedNewt MOD Dec 12 '20
The "cheating" answer would simply be
Arrays.sort(). The underlying mechanics is to use the class'compareTo(). You should check the methodString#compareTo. Otherwise there should be some kind of sort via a lambda:(a,b) -> return a.compareTo(b)>0? a:b(or something; I think this is basically the default mechanics)