I have a list:
public static List<String> codes = new LinkedList<String>(Arrays.asList(
"Zero",
"One"
)); //Etc..
I want to be able to find the number of a String
's position when I type it. For instance, if I type One
, I want the program to print out 1
. Currently, I can only do the reverse by using codes.get();
Correction: I want the program to print out the position of the String in the list. Zero
has the position 0
, if I do codes.get(0);
I get Zero
. But how do I do the reverse?
Is there a way to smoothly do this? Thanks in advance.
The reverse of codes.get()
is indexOf(Object obj)
method
Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.
codes.indexOf("One");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With