Help with TreeSet and finding longest string
Well due to sickness I missed a week of college which means I missed out on a lecture Im using something called TreeSet which seems to group things. Anywho I need to get the longest name in a list of names. Here is my code:
Code:
import java.util.*;
/** demonstrates Set and SortedSet via a list of names
*/
public class NameSet {
public static void main (String args[]){
Set<String> names = new HashSet<String>();
names.add("Bernadine");
names.add("Elizabeth");
names.add("Gene");
names.add("Elizabeth");
names.add("Clara");
System.out.println(names);
// transfer all the names to a (sorted) TreeSet
TreeSet<String> sortedNames = new TreeSet<String>(names);
System.out.println(sortedNames);
System.out.println("First person is " +sortedNames.first());
System.out.println("longest name is ")+sortedNames.
}
}
Code end.
Ps Im not being lazy I just want a straightforward answer as I dont get it