File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SortNames output

 
K. Tsang
Bartender
Pie
Posts: 3228
12
Android Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3228
12
Android Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic