About 1,030,000 results
Open links in new tab
  1. arrays - Definition of a index variable in java - Stack Overflow

    Mar 10, 2016 · The index of an array element is the number in the brackets, []. In the example, alpha[2] = 3, 2 is the index and 3 is the variable stored at index 2. Also remember that for arrays, index 2 means that it is the third position in the array because the first index is position 0.

  2. java - How to use an index variable in a recursion ... - Stack Overflow

    May 12, 2012 · I want to use an index variable inside a recursion, without sending it as a parameter when calling the function. However, if I reset it at the beginning (e.g i = 0), it will reset on every run. I want to use it as a counter (to count the function runs).

  3. java - Calling method with array index - Stack Overflow

    Jun 26, 2019 · In my opinion, to call the static method getArray it is necessary to write: getArray();... without the index! I considered this code with a compiler error. Can you explain me why getArray() [index =2]++; compiles without errors?

  4. Java String indexOf() Method - W3Schools

    The indexOf() method returns the position of the first occurrence of specified character(s) in a string. Tip: Use the lastIndexOf method to return the position of the last occurrence of specified character(s) in a string.

  5. 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.

  6. Find the Index of an Array Element in Java - GeeksforGeeks

    Dec 9, 2024 · One of the simplest and most straightforward ways to find the index of an element in an array is by using a loop. You can iterate through the array and compare each element with the target element. When a match is found, you return the index. Here, we have used linear search in an array, the element can be found in O (N) complexity. 2.

  7. 7.2. Traversing Arrays with For Loops — CS Java

    Jul 2, 2010 · Index Variables¶ In the last lesson, we mentioned that you can use a variable for the index of an array. You can even do math with that index and have an arithmetic expression inside the [], like below.

  8. Java Array Find Index of Element – [Tutorial] - HatchJS.com

    In Java, you can find the index of an element in an array using the `indexOf ()` method. The `indexOf ()` method takes two arguments: the array to search and the element to find. The method returns the index of the element in the array, or -1 if the element is not found.

  9. What is an index variable? – Quick-Advisors.com

    Jan 24, 2021 · Index variables can be used as grouping variables in procedures. What is meant by index of an element in Java? The indexOf() method of ArrayList returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. Syntax : public int IndexOf(Object o) obj : The element to search for ...

  10. How to Get the Index of an Element in an Array in Java

    Dec 26, 2023 · The following code shows how to get the index of an element in an array using the `indexOf()` method: java int index = array.indexOf(element); For example, the following code gets the index of the element “apple” in the array `fruits`: java int index = fruits.indexOf(“apple”);

  11. Some results have been removed