This post originated from an RSS feed registered with Java Buzz
by Javin Paul.
Original Post: How to find index of item in Array in Java
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
While programming in Java, many times we need to check if an String
array contains a particular String
or an int array contains a number or not. Though array is an object in Java but
it does not provide any convenient method to perform these kind of operation.
Some time you even need index of an item stored in Array, unfortunately Java
API does not provide any direct method. Thanks to open Source Apache Commons
provides a utility class called ArrayUtils which
allows you to check for an Item in Array,
find its index in array, find its lastIndex in Array and perform several other
common operations. In fact ArrayUtils has overloaded
methods for different kind of Array e.g. String, int, float, double, Object
etc, which makes this kind of programming task trivial. In this article we will
see an Apache commons example of How to
use ArrayUtils class to search an item in Arrayand find its index.