I'm trying to find out if there is an easier way to map two string arrays in Java. I know in Python, it's pretty easy in two lines code. However, i'm not sure if Java provides an easier option than looping through both string arrays.
String [] words = {"cat","dog", "rat", "pet", "bat"};
String [] numbers = {"1","2", "3", "4", "5"};
My goal is the string "1" from numbers to be associated with the string "cat" from words, the string "2" associated with the string "dog" and so on.
Each string array will have the same number of elements.
If i have a random given string "rat" for example, i would like to return the number 3, which is the mapping integer from the corresponding string array.
Something like a dictionary or a list. Any thoughts would be appreciated.