aspose file tools*
The moose likes Java in General and the fly likes index of an element in an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "index of an element in an array" Watch "index of an element in an array" New topic

index of an element in an array

krishna prasad gunasekaran
Ranch Hand

Joined: Jul 25, 2006
Posts: 158
good day,
hw to find the index of an element in an array.

have a great day,
krishna prasad
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

java.util.List has an indexOf method (providing your equals method is implemented correctly), and can convert from an Array to a List using java.util.Arrays.asList
Henry Wong

Joined: Sep 28, 2004
Posts: 18135

Well, if the elements of the array are sorted, then you could use the java.util.Arrays class. Otherwise, I believe you have to loop through the array to find the element that you want.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: index of an element in an array
Similar Threads
Array elements
variable of interest
mock exam question
Deleting duplicate element in an array