This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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


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
Author

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
Rancher

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
author
Sheriff

Joined: Sep 28, 2004
Posts: 20019
    
  44

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.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: index of an element in an array
 
jQuery in Action, 3rd edition