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 2 of 2

Thread: How to sort a Map.Entry in a for loop?

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to sort a Map.Entry in a for loop?

    Hello, I have this Map in a for loop:
    for (Map.Entry<String, List<String>> entry : storage.entrySet()) {
                sendGroupStrings(sender, entry.getValue(), entry.getKey());
            }

    The issue is, whenever the method sendGroupStrings() is ran, it displays the data randomly. I need to sort the data(alphabetically) in the entry map in order to display those strings properly. Now, I've already tried using a TreeMap, but I was unable to find a way to get the Key data(which is required in sendGroupStrings()) in order to make it work. However, I am open to other suggestions.

    Basically, I need the data to be pulled from entry, sorted alphabetically, and then ran through sendGroupStrings().


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to sort a Map.Entry in a for loop?

    You need to look through the choice of classes and methods in the collection framework to find the combination that will do what you want.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How do I sort strings without using the sort method?
    By mjballa in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 4th, 2011, 03:27 PM
  2. Table with CustomModel when clicked shows old entry
    By Nesh108 in forum AWT / Java Swing
    Replies: 6
    Last Post: November 9th, 2011, 06:38 AM
  3. need help w/ entry level homework...
    By rbread80 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 3rd, 2010, 10:24 PM
  4. bubble sort and selection sort on strings
    By Sir Saula in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 3rd, 2010, 09:44 AM
  5. how to add a new entry in a current array
    By chronoz13 in forum Java Theory & Questions
    Replies: 1
    Last Post: December 28th, 2009, 06:39 PM