In Java is there a method to find index of a particular string in ArrayList?
For Example if cities is an array list of 100 cities and I want to find the index of "New York".
Asked
Active
Viewed 124 times
-1
Auto
- 1
- 3
-
3some googling effort would show you that there is an `indexOf` method – Mohammed Aouf Zouag Nov 15 '15 at 14:56
1 Answers
0
You can use the indexOf(...) method for search in ArrayList. If the String exists within the ArrayList, it returns the index of the String, otherwise it returns -1.
This link might be helpful.
Turing85
- 18,217
- 7
- 33
- 58
Mohsen_Fatemi
- 2,183
- 2
- 16
- 25