
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
ints indexOf Function in Java
The indexOf() method of the Ints class returns the index of the first appearance of the value target in array. The syntax is as follows −
public static int indexOf(int[] arr, int target)
Here, parameter arr is an array of int values and target is the value to be checked for first appearance.
Let us now see an example −
Example
import com.google.common.primitives.Ints; class Demo { public static void main(String[] args) { int[] arr = { 10, 20, 30, 40, 50, 60,70, 80, 90, 100 }; int index = Ints.indexOf(arr, 40); if (index != -1) { System.out.println("Element 40 is in the array at position " + (index+1)); } else { System.out.println("Element 40 is not in the array"); } } }
Output
Element 40 is in the array at position 4
Advertisements