🌐
W3Schools
w3schools.com › java › ref_arraylist_indexof.asp
Java ArrayList indexOf() Method
public int indexOf(Object item) Java Arrays Tutorial · Java ArrayList Tutorial · ❮ ArrayList Methods · ★ +1 · Sign in to track progress · REMOVE ADS · PLUS · SPACES · GET CERTIFIED · FOR TEACHERS · BOOTCAMPS · CONTACT US · × · If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com ·
🌐
W3Schools
w3schools.com › java › java_arraylist.asp
Java ArrayList
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... An ArrayList is like a resizable array.
🌐
W3Resource
w3resource.com › java-tutorial › arraylist › arraylist_indexof.php
Java ArrayList.indexOf() Method
August 19, 2022 - Return Value: The index of the first occurrence an element in ArrayList, or -1 if the element does not exist. ... The following example creates an ArrayList containing various colors.
🌐
W3Schools
w3schools.com › java › java_ref_arraylist.asp
Java ArrayList Reference
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... A list of all ArrayList methods can be found in the table below. Some methods use the type of the ArrayList's items as a parameter or return value. This type will be referred to as T in the table. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-get-method-java-examples
ArrayList get(index) Method in Java with Examples - GeeksforGeeks
December 10, 2024 - Example 2: Here, we will demonstrate the error when attempting to access an index that is out of range. ... // Java program to demonstrate error generated // while using get() method in ArrayList import java.util.ArrayList; public class GFG { public static void main(String[] args) { // Creating an ArrayList of Integers ArrayList<Integer> arr = new ArrayList<Integer>(4); // Adding elements to the ArrayList arr.add(10); arr.add(20); arr.add(30); arr.add(40); // Trying to access an element // at an invalid index int e = arr.get(5); // Printing the element at // index 5 (will throw exception) System.out.println("The element at index 5 is " + e); } }
🌐
W3Schools
w3schools.com › java › ref_arraylist_get.asp
Java ArrayList get() Method
public T get(int index) T refers to the data type of items in the list. Java Arrays Tutorial · Java ArrayList Tutorial · ❮ ArrayList Methods · ★ +1 · Sign in to track progress · REMOVE ADS · PLUS · SPACES · GET CERTIFIED · FOR TEACHERS ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-util-arraylist-indexof-java
Java Arraylist indexOf() Method - GeeksforGeeks
December 10, 2024 - Example 1: Here, we will use the indexOf() method to find the index of a specific element in an ArrayList. ... // Java program to demonstrate the // use of indexOf() method import java.util.ArrayList; public class GFG { public static void ...
🌐
Codecademy
codecademy.com › docs › java › arraylist › .indexof()
Java | ArrayList | .indexOf() | Codecademy
February 12, 2023 - The .indexOf() method returns the index of the first occurrence of the specified element in an ArrayList. If the element is not found, -1 is returned. ... Looking for an introduction to the theory behind programming?
🌐
W3Schools
w3schools.com › java › java_list.asp
Java List
The List interface is part of the Java Collections Framework and represents an ordered collection of elements. You can access elements by their index, add duplicates, and maintain the insertion order. Since List is an interface, you cannot create a List object directly. Instead, you use a class that implements the List interface, such as: ArrayList - like a resizable array with fast random access
Find elsewhere
🌐
W3Schools
w3schools.com › java › ref_arraylist_lastindexof.asp
Java ArrayList lastIndexOf() Method
import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<String> cars = new ArrayList<String>(); cars.add("Volvo"); cars.add("Ford"); cars.add("BMW"); cars.add("Ford"); cars.add("Mazda"); System.out.println(cars.indexOf("Ford")); System.out.println(cars.lastIndexOf("Ford")); } } Try it Yourself » ·
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › java arraylist.indexof()
Java Arraylist.indexOf() - Get Element Index - HowToDoInJava
January 13, 2023 - We can use this method to find if an object is present in the arraylist. If the object is present, then the return value will be greater than '-1‘. Happy Learning !! ... What happens if two objects in the list are the same. I know it would print the index of the first occurrence, but how ...
🌐
TutorialsPoint
tutorialspoint.com › get-the-index-of-a-particular-element-in-an-arraylist-in-java
Java ArrayList indexOf() Method
September 13, 2023 - We're adding couple of Integers to the ArrayList object using add() method calls per element and using indexOf(object) method, we're checking index of an element and printing it. package com.tutorialspoint; import java.util.ArrayList; public ...
🌐
W3Schools
w3schools.com › java › ref_arraylist_sublist.asp
Java ArrayList subList() Method
import java.util.ArrayList; public ... cars.subList(1, 3) ); } } ... The subList() method returns a new list (referred to as a sublist) which contains the items of the list between two indices....
🌐
Programiz
programiz.com › java-programming › library › arraylist › indexof
Java ArrayList indexOf()
Here, the indexOf() method successfully returns the position of element 13. However, the element 50 doesn't exist in the arraylist. Hence, the method returns -1. import java.util.ArrayList; class Main { public static void main(String[] args) { // create an ArrayList ArrayList<String> languages ...
🌐
TutorialsPoint
tutorialspoint.com › java › util › arraylist_get.htm
Java ArrayList get() Method
The Java ArrayList get(int index) method returns the element at the specified position in this list. Index starts from 0 like first element can be retrieved using get(0) method call and so on.
🌐
Vultr
docs.vultr.com › java › standard-library › java › util › ArrayList › indexOf
Java ArrayList indexOf() - Find Element Index | Vultr Docs
September 27, 2024 - Create a list of custom objects and use indexOf() to find the index of a specific object. ... import java.util.ArrayList; class Fruit { String name; public Fruit(String name) { this.name = name; } @Override public boolean equals(Object obj) ...
🌐
W3Resource
w3resource.com › java-tutorial › arraylist › arraylist_get.php
Java arraylist get method - w3resource
August 19, 2022 - import java.util.*; public class test { public static void main(String[] args) { // create an empty array list with an initial capacity ArrayList<String> color_list = new ArrayList<String>(5); // use add() method to add values in the list color_list.add("White"); color_list.add("Black"); color_list.add("Red"); color_list.add("White"); color_list.add("Yellow"); // Print out the colors in the ArrayList. for (int i = 0; i < 5; i++) { System.out.println(color_list.get(i).toString()); } } } ... Example of Throws: get() Method IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()). ... White Black Red White Yellow Exception in thread "main" java.lang.IndexOutOfBoundsEx ception: Index: 5, Size: 5 at java.util.ArrayList.rangeCheck(ArrayList.jav a:635) at java.util.ArrayList.get(ArrayList.java:411) at test.main(test.java:19)
🌐
W3Schools
w3schools.com › java › ref_arraylist_set.asp
Java ArrayList set() Method
public T set(int index, T item) T refers to the data type of items in the list. Java Arrays Tutorial · Java ArrayList Tutorial · ❮ ArrayList Methods · ★ +1 · Sign in to track progress · REMOVE ADS · PLUS · SPACES · GET CERTIFIED ...