Christian Proschek Christian Proschek - 1 year ago 99
Java Question

The opposite of .get() (ArrayList)

I would just like to ask,

I have an arraylist and I have a String.

When I use .get(Int), I get the String!

Now how would I get that Integer from a String?

Thanks in advance,


Answer Source

You can use the .indexOf(Object o) method which returns, as the java 8 documentation specifies:

the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element

You can also use .lastIndexOf(Object o) which, as you would guess, will return the last occurrence of the specified element.

Please consult the documentation for more details.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download