Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Returning a list in a specified order

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Returning a list in a specified order

    I'm very new to Java and have been learning through online tutorials thus far getting some of the basics down. I was asked to create a list that would return names by order of age.
    I don't even know where to really begin with this code as I've yet to learn how to do so. I'm not asking anyone to write the code for me but I'd like to know where to start or a resource to learn what method to use for returning a list ordered by a specific parameter. Basically the directions go like this:

    "Create a class called Department which will contain a list of employees.
    a) Department class will have a method which will return its employees ordered by age."

    Any help would be deeply appreciated. Am I working with an array?


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: Returning a list in a specified order

    No, you'll be using a List. Collections.sort() can sort that List. You have to specify a Comparator.

    So, google the above in conjunction with Java: "List Java" etc.

  3. #3
    Member
    Join Date
    Sep 2013
    Posts
    70
    Thanks
    1
    Thanked 13 Times in 13 Posts

    Default Re: Returning a list in a specified order

    Well a few things you have to do:
    1. Figure out how you will be storing your variables (names, ages, etc...)
    2. What will you be using to store this data? (Array, List, Binary Tree)
    3. Figure out how the data will be accessed and sorted.

    It won't be to difficult once you know what you want to do. Anything you get stuck on you can always post questions about. As long as you are trying and not expecting for us to do the work for you we will gladly help you out.

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Returning a list in a specified order

    Are you allowed to use Collections.sort() or do you have to implement the sorting yourself?
    Improving the world one idiot at a time!

  5. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Returning a list in a specified order

    Thank you for the replies.

    I believe I can use Collections.sort(). Been looking up how to use that method for what I'm trying to achieve and feel like I'm biting off more than I can chew at my current skill level.

Similar Threads

  1. Knapsack problem , check if matrix can fill list of smaller matrix list.
    By ofirattia in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 8th, 2012, 01:20 PM
  2. [SOLVED] Alphabetical order
    By sbjibo in forum What's Wrong With My Code?
    Replies: 12
    Last Post: May 16th, 2012, 03:20 PM
  3. Linked list Schminked list help with Nodes Please
    By Bially in forum Collections and Generics
    Replies: 1
    Last Post: September 29th, 2011, 03:20 PM
  4. SpinnerListModel setList(List<?> list)
    By roy epperson in forum Collections and Generics
    Replies: 4
    Last Post: November 29th, 2010, 10:30 AM
  5. Stack Order?
    By TimW in forum AWT / Java Swing
    Replies: 2
    Last Post: September 19th, 2009, 07:33 AM