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

  • Home
  • SEARCH
  • 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 8444019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:17:47+00:00 2026-06-10T09:17:47+00:00

I have retrieved data from a 2-column CSV file using HashMap. This is for

  • 0

I have retrieved data from a 2-column CSV file using HashMap. This is for use in a dictionary-style app – one column contains terms and the second contains definitions, which are linked to the terms by the HashMap.

The first thing my app does is print out the list of terms as a list. However, they seem to all come out in a random order.

I’d like them to remain in the same order that they were in in the CSV file (I won’t rely on any alphabetising methods, since I have the occasional non-standard characters and would prefer to alphabetise at the source)

Here’s my code, which extracts the data from the CSV file and prints it to a list:

  String next[] = {}; // 'next' is used to iterate through dictionaryFile
  final HashMap<String, String> dictionaryMap = new HashMap<String, String>(); // initialise a hash map for the terms

  try {
        CSVReader reader = new CSVReader(new InputStreamReader(getAssets().open("dictionaryFile.csv")));
        while((next = reader.readNext()) != null) { // for each line of the input file
            dictionaryMap.put(next[0], next[1]); // append the data to the dictionaryMap
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

  String[] terms = new String[dictionaryMap.keySet().size()]; // get the terms from the dictionaryMap values
  terms = dictionaryMap.keySet().toArray(terms);

  setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, terms));
  ListView lv = getListView();

This causes the app to load, with the terms in place, but they are in a completely obscure order. How do I get them to print in the same order they originally were in?

  • 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-06-10T09:17:48+00:00Added an answer on June 10, 2026 at 9:17 am

    The problem is that a normal HashMap does not guarantee the order. This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.

    Try using a LinkedHashMap, it will maintain the insertion order.

    From the documentation – Hash table and linked list implementation of the Map interface, with predictable iteration order

    Here is a link to the docs – http://docs.oracle.com/javase/6/docs/api/java/util/LinkedHashMap.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data from an excel file which contains one column as DateTime with
I have this code to display the data retrieved from DB in accounts_view.php :
Using MySQL Administrator GUI tool I have exported some data tables retrieved from an
I'm supposed to add data from my csv file into my database. I have
We have an item cull that retrieves items and their appropriate data from one
I have a CSV with keywords in one column and the number of impressions
In my grails application I have an sql query that selects column data from
I have stored values retrieved from a text file into an array. Now am
I have some existing code that retrieves data from a database using ADO.NET that
I have a problem in getting some data out from Cassandra using c# and

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.