Java Guava | Ints.indexOf(int[] array, int[] target) method with Examples Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Ints.indexOf(int[] array, int[] target) method of Guava's Ints Class accepts two parameters array and target. If the target exists within the array, the method returns the start position of its first occurrence. If the target does not exist within the array, the method returns -1. Syntax: public static int indexOf(int[] array, int[] target) Parameters: The method accepts two parameters: array: which is the integer array in which the target array is to checked for index. target: which is the array to be searched for as a sub-sequence of specified array. Return Value: The method returns an integer value as follows: It returns the start position of first occurrence of the target if the target array exists in the array. Else it returns -1 if the target does not exist in the array. Exceptions: The method does not throw any exception. Below examples illustrate the implementation of above method: Example 1: Java // Java code to show implementation of // Guava's Ints.indexOf(int[] array, // int[] target) method import com.google.common.primitives.Ints; import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Creating an integer array int[] arr = { 1, 2, 3, 4, 3, 5 }; int[] target = { 3, 4, 3 }; System.out.println("Array: " + Arrays.toString(arr)); System.out.println("Target Array: " + Arrays.toString(target)); // Using Ints.indexOf(int[] array, int[] target) // method to get the start position of the first // occurrence of the specified target within array, // or -1 if there is no such occurrence. int index = Ints.indexOf(arr, target); if (index != -1) { System.out.println("Target is present at index " + index); } else { System.out.println("Target is not present " + "in the array"); } } } Output: Array: [1, 2, 3, 4, 3, 5] Target Array: [3, 4, 3] Target is present at index 2 Example 2: Java // Java code to show implementation of // Guava's Ints.indexOf(int[] array, // int[] target) method import com.google.common.primitives.Ints; import java.util.Arrays; class GFG { // Driver's code public static void main(String[] args) { // Creating an integer array int[] arr = { 3, 5, 7, 11, 13 }; int[] target = { 23, 37 }; System.out.println("Array: " + Arrays.toString(arr)); System.out.println("Target Array: " + Arrays.toString(target)); // Using Ints.indexOf(int[] array, int[] target) // method to get the start position of the first // occurrence of the specified target within array, // or -1 if there is no such occurrence. int index = Ints.indexOf(arr, target); if (index != -1) { System.out.println("Target is present at index " + index); } else { System.out.println("Target is not present" + " in the array"); } } } Output: Array: [3, 5, 7, 11, 13] Target Array: [23, 37] Target is not present in the array Reference: https://guava.dev/releases/22.0/api/docs/com/google/common/primitives/Ints.html#indexOf-int:A-int:A- Comment More infoAdvertise with us Next Article Java Tutorial S Sahil_Bansall Follow Improve Article Tags : Java java-guava Guava-Functions Guava-Ints Practice Tags : Java Similar Reads Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Java s 10 min read Java OOP(Object Oriented Programming) Concepts Java Object-Oriented Programming (OOPs) is a fundamental concept in Java that every developer must understand. It allows developers to structure code using classes and objects, making it more modular, reusable, and scalable.The core idea of OOPs is to bind data and the functions that operate on it, 13 min read Java Interview Questions and Answers Java is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per 15+ min read Arrays in Java In Java, an array is an important linear data structure that allows us to store multiple values of the same type. Arrays in Java are objects, like all other objects in Java, arrays implicitly inherit from the java.lang.Object class. This allows you to invoke methods defined in Object (such as toStri 9 min read Collections in Java A collection in Java is a group of individual objects that are treated as a single unit. In Java, a separate framework named the "Collection Framework" was defined in JDK 1.2, which contains all the Java Collection Classes and interfaces. In Java, the Collection interface (java.util.Collection) and 12 min read Inheritance in Java Java Inheritance is a fundamental concept in OOP(Object-Oriented Programming). It is the mechanism in Java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, Inheritance means creating new classes based on existing ones. A class that inherits from an 9 min read Java Exception Handling Exception handling in Java is an effective mechanism for managing runtime errors to ensure the application's regular flow is maintained. Some Common examples of exceptions include ClassNotFoundException, IOException, SQLException, RemoteException, etc. By handling these exceptions, Java enables deve 8 min read Java Programs - Java Programming Examples In this article, we will learn and prepare for Interviews using Java Programming Examples. From basic Java programs like the Fibonacci series, Prime numbers, Factorial numbers, and Palindrome numbers to advanced Java programs.Java is one of the most popular programming languages today because of its 8 min read Introduction to Java Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is platform-independent, which means we can write code once and run it anywhere using the Java Virtual Machine (JVM). Java is mostly used for building desktop applications, web applications, Android 4 min read Java Interface An Interface in Java programming language is defined as an abstract type used to specify the behaviour of a class. An interface in Java is a blueprint of a behaviour. A Java interface contains static constants and abstract methods. Key Properties of Interface:The interface in Java is a mechanism to 12 min read Like