I have an array of strings plus one additional string. I want to use this string and values of array to get a set of string. Then I want to order the set of string alphabetically and extract the string which is the first in the list. What is the easiest way to do it in Java?
ADDED:
I wanted to do it this way:
List<String> playersList = Arrays.asList(players);
playersList.add(userName); // <---------- HERE IS A PROBLEM
Collections.sort(playersList);
I do not get any errors during the compilation. But during the execution I get a “UnsopportedOperationException”. And it happens in the second line.
If you just want to get the minimum of an array of
Stringwith an additional external element, then you don’t have to sort and extract first (which would beO(N log N)). You can do it inO(N).