0

I have a requirement in which I am iterating a list using a for loop and getting the values of a device like model number(3-digit number),directory number etc. The model number which I got should be compared/search with a CSV file(it has 2 columns-compared with one column-3-digit model number) and need to find its corresponding value in the other column.Once it finds the value it should display that value in the list instead of the 3-digit number.I think I create a hashmap after reading the csv file and pull the output from the hashmap.

Can you let me know if my approach is correct and if so can I get a sample code as how I need to do this? thank you so much in advance. Language-Java

javalearner
  • 197
  • 2
  • 4
  • 16
  • 2
    if you are asking for a solution, I don't think anyone is here to do your assignment. – JuliandotNut Jul 25 '14 at 21:49
  • Does this answer your question? [Convert CSV values to a HashMap key value pairs in JAVA](https://stackoverflow.com/questions/20068383/convert-csv-values-to-a-hashmap-key-value-pairs-in-java) – S S Apr 05 '22 at 05:50

1 Answers1

2

Yes if you have one CSV file has a mapping of the model number to something you can load that into a HashMap with the key being the model number and the value whatever it is you want to show instead.

To initialize a HashMap;

HashMap<String, String> hashMap = new HashMap<String, String>();

To add to it when you read your first CSV file;

hashMap.put(key, value);

And to retrieve the value based on the key when handling the other CSV file.

String value = hashMap.get(key);

For more info on HashMap; http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html

Doswell
  • 418
  • 3
  • 11