• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SortNames output

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic