Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7070625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:35:21+00:00 2026-05-28T05:35:21+00:00

Possible Duplicate: Iterating through a LinkedHashMap in reverse order How to traverse Linked Hash

  • 0

Possible Duplicate:
Iterating through a LinkedHashMap in reverse order

How to traverse Linked Hash Map in a reverse order? Is there any predefined method in map to do that?

I’m creating it as follows:

LinkedHashMap<Integer, String> map = new LinkedHashMap<Integer,String>();
map.put(1, "one");
map.put(2, "two");
map.put(3, "three");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:35:22+00:00Added an answer on May 28, 2026 at 5:35 am
    List<Entry<Integer,String>> list = new ArrayList<>(map.entrySet());
    
    for( int i = list.size() -1; i >= 0 ; i --){
        Entry<Integer,String> entry = list.get(i);
    }
    

    Not really pretty and at the cost of a copy of the entry set, which if your map has a significant number of entries might be a problem.

    The excellant Guava library have a [List.reverse(List<>)][2] that would allow you to use the Java 5 for each style loop rather than the indexed loop:

    //using guava
    for( Entry entry : Lists.reverse(list) ){
        // much nicer
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: for vs foreach vs while which is faster for iterating through arrays
Possible Duplicate: (C#) Get index of current foreach iteration Good morning, Is there any
Possible Duplicate: Can you remove elements from a std::list while iterating through it? I
Possible Duplicate: C# Iterating through an enum? (Indexing a System.Array) All I want to
Possible Duplicate: Can you remove elements from a std::list while iterating through it? I
Possible Duplicate: Can one do a for each loop in java in reverse order?
Possible Duplicate: How to determine if a linked list has a cycle using only
Possible Duplicate: What's the difference between iterating over a file with foreach or while
Possible Duplicate: Python: Adding element to list while iterating This doesn't seem to work,
Possible Duplicate: Can every recursion be converted into iteration? Are there problems in which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.