This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
You want the corresponding index of an element in your array. Unfortunately there's no way an array directly supports this. You would have to search through the array each time you want to know an index. But that's probably not the best idea.
I'd recommend you to use one of the List classes provided by the collections framework. The List interface has a method indexOf(Object o) which directly gives you the index of an object in your list. In contrast to an array you have to use wrapper classes like Integer when using collections but with auto-boxing this shouldn't be a problem
It's not that different to other collections classes. Just use the following and the above example of Anubhav works as well:
Anyway Vector was adapted to implement the List interface as of Java v1.2 so there's no big difference despite the internal advantages and disadvantages of each List implementation regarding synchronization or performance.
If switching to a class in the Collections Framework isn't an option, you could always use the appropriate overloaded binarySearch() method of the java.util.Arrays class to retrieve the index of a specific element quite efficiently.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.