It's not a secret anymore!*
The moose likes Cattle Drive and the fly likes SortNames output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "SortNames output" Watch "SortNames output" New topic
Author

SortNames output

K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2627
    
    9

Hello all, I'm just wondering what's the correct output to OOP3 (SortNames)? I got the following using ArrayList:

[Abraham Lincoln, Adam Baum, Bill Joy, Connie Chung, James Gosling, Joe Montana, Justin Case, Walter Cronkite]

Or is it something else? Thanks


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Hello K,

From the instructions, the output should be "Show the names sorted in order of first name and then by last name."

It looks like you got a list of names sorted by first name. Sorting by last name may be a bit trickier...


Happy coding,
Pauline
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2627
    
    9

For the sort by last name output, does the name needs to be "firstname lastname"? Because, I swapped the 2 and sorted it. But not sure if the output needs to be reversed for each name.

Also when I compile my program, I got a note saying the program uses unchecked or unafe operations, recompile with -Xlint:unchecked for details. When I do recompile, it warns about my ArrayList.add and Collections.sort: ArrayList.add(<some string>) and Collection.sort(<some arraylist>). According to the API, ArrayList.add(Element) and Collections.sort(List<T>).

This makes me wonder isn't an arraylist a list and can string be element? If not to either, how to ensure it is a list or element respectively? casting? Any help on this is appreciated. Thanks
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
For the sort by last name output, does the name needs to be "firstname lastname"? Because, I swapped the 2 and sorted it. But not sure if the output needs to be reversed for each name.

The output should be "firstname lastname". You should not change the list or create a new list to get the correct output.

Also when I compile my program, I got a note saying the program uses unchecked or unafe operations, recompile with -Xlint:unchecked for details. When I do recompile, it warns about my ArrayList.add and Collections.sort: ArrayList.add(<some string>) and Collection.sort(<some arraylist>). According to the API, ArrayList.add(Element) and Collections.sort(List<T>).

This makes me wonder isn't an arraylist a list and can string be element? If not to either, how to ensure it is a list or element respectively? casting?


If you only got warnings, but were able to compile and run the class, you don't need to worry. The warnings were added in jdk-5 for jdk-5-specific syntax.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
jQuery in Action, 2nd edition
 
subject: SortNames output