1

I am facing difficulties in mapping the values of two arrays to each other. I am having a string array list which is storing the users selected values:

private List<String> selectedCertificates = new ArrayList<String>();

The above array will store as an example ["SS", "CC", "SC"] and at the same time the user can select a language for certain types but not all of them. For example the type "SS" and the type "CC" should be by default "English" where "SC" can be either English or French or any other language.

        String[] DocType = new String[4];
        String[] DocLanguage = new String[4];

        DocType[0] = "CE";
        DocLanguage[0] = "EN";
        DocType[1] = "SC";
        DoctLanguage[1] = "EN";
        DocType[2] = "SS";
        DocLanguage[2] = ssLanguage;
        DocType[3] = "RR";
        DocLanguage[3] = "FR";

So now my issue is that I want to have a string array for the selected languages only that it will include ["EN","EN",valueofssLanguage] for the same sequence of the selected certificates ["SS", "CC", "SC"], so how can I achieve this?

Thanks

3
  • Hashmap, Hashtable can map from string to string. Commented Mar 29, 2015 at 17:37
  • Map should fit your needs Commented Mar 29, 2015 at 17:38
  • So what should I do I need some guidance. Commented Mar 29, 2015 at 17:38

1 Answer 1

1

Use a java.util.Map:

Map<String, String> map = new HasMap<>();
map.put(docType[0], "EN");
...

You can use Map#values() to get a collection view of the values, that is a collections of languages.

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

5 Comments

Should I replace the my code with the above suggested? And how do I get the selectedLanguages in a separate string array?
Thanks for the help, but will the map will get the values of the languages once the certificates are selected?
@Learner30 You can retrieve the language corresponding to a specific certificate using Map.get(certificate). See the Javadoc for info about map operations.
Yes it seems Map is the best choice here.
manouti, correct me if I am wrong. First I will do the mapping as how you specified above in your answer. Then, I would use map.get(selectedCertificates) to get the selected mappings, am I correct? Should I keep it in a for loop? Also, should I delete DocType[0] = "CE"; from my code?

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.