About 357,000 results
Open links in new tab
  1. Find the Index of an Array Element in Java - GeeksforGeeks

    Dec 9, 2024 · In Java, to get the first element in an array, we can access the element at index 0 using array indexing. Example 1: Below is a simple example that demonstrates how to access the element at index 0 in an array.

  2. How to find the index of an element in an array in Java?

    Nov 9, 2011 · Starting with Java 8, the general purpose solution for a primitive array arr, and a value to search val, is: public static int indexOf(char[] arr, char val) { return IntStream.range(0, arr.length).filter(i -> arr[i] == val).findFirst().orElse(-1); }

  3. How to Get the Index of a Specified Element in an Array in Java?

    Dec 9, 2024 · In Java, to find the index of a specific element in an array, we can iterate through it and checking each element. There are several ways to achieve this, including using loops, utility functions, Arrays.asList() for non-primitive arrays, and Streams.

  4. Arrays in Java - GeeksforGeeks

    Mar 28, 2025 · We can access array elements using their index, which starts from 0: The first line sets the value of the first element to 10. The second line retrieves the value of the first element. 4. Change an Array Element. To change an element, assign a new value to …

  5. Find the Index of an Element in a Java Array - Baeldung

    Dec 7, 2023 · In this tutorial, we’ll discuss various methods, with code examples, for finding the index of an array element using both Java’s built-in APIs and a third-party library. This can be useful for many tasks, including searching, sorting, and modifying arrays.

  6. Indexing in java arrays - Stack Overflow

    Jan 10, 2015 · Do you want to fill an array t with one value of s [i]? I presume you mean something like t[j] = s[j + idx + 1]? Well you want to copy all the remaining values, and create an array of index t. Thus you need to start with i=0. You can however perform a shift-operation: increase i somewhere, and when you use it, shift it back, so: t[i-idx-1] = s[i];

  7. java - How to find the index of an element in an int array? - Stack ...

    May 30, 2011 · If you don't want to sort the array, just use a simple for loop to find the value. It is generally good to read documentation of functions :) From binarySearch: "Searches the specified array of ... for the specified value using the binary search algorithm. The array must be sorted (as by the sort (long []) method) prior to making this call.

  8. Find The Index of An Array Element in Java - Tpoint Tech

    In this tutorial, we will see how one finds the index of an array element in Java. To avoid confusion, we will assume that all the elements of the array are unique. In other words, no element will occur more than once. In the input, an array and a number k will be given to us. We have to have the index of the element k in the array.

  9. Find index of an element in given array in Java | Techie Delight

    Mar 27, 2024 · This post will discuss how to find the index of an element in a primitive or object array in Java. The solution should either return the index of the first occurrence of the required element or -1 if it is not present in the array. 1. Naive Solution – Linear search.

  10. How to find index of Element in Java Array? - Tutorial Kart

    How to find index of Element in Java Array? You can find the index of an element in an array in many ways like using a looping statement and finding a match, or by using ArrayUtils from commons library. In this tutorial, we will go through each of these process and provide example for each one of them for finding index of an element in an array.