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

2

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much for your answer.I am a beginner and still learning.Your pointers really helps.Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.