
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
Found 7442 Articles for Java

9K+ Views
To iterate over a List using a for loop, we need to know the size (which can be calculated using the size() method) of the list, so that the loop can execute an accessing element code block till the last position, which is starts from index 0. Once the loop reaches at the last index of the list, it will stop executing and exit. Here are a few examples of how to iterate over a list using a for loop: Iterate a List using For Loop A for-loop is a "control flow statement " which is ... Read More

513 Views
The List interface extends the Collection interface and is an important member of Java Collections Framework. List interface declares the behavior of a collection that stores a sequence of elements. The most popular implementation of List interface is ArrayList. User of a list has quite precise control over where an element to be inserted in the List. These elements are accessible by their index and are searchable. List provides two methods to efficiently add element in a list.List interface provides a method iterator() to get an Iterator instance to iterate through its elements and listIterator() method to get a more ... Read More

4K+ Views
A List is a sequence of elements of similar data types, and like an array, its elements are stored at specific indices, which can be accessed and searchable through the index (i.e., starting at index 0). We can search through each element in the list and retrieve its index (or position) if it is found in the list. We can search in a List in the following ways - Using indexOf() Method of List Interface Using lastIndexOf() Method Using Comparison Approach Searching in a List using ... Read More

576 Views
The article will discuss different ways to remove elements from an ArrayList. Below is a list of methods that can help in removing elements from an ArrayList: Using the remove() Method of List Interface Using the remove(object) Method Using the clear() Method Using the removeAll() Method Removing a Single Element using the remove() Method The remove() method of the List interface accepts an integer value representing an index as a parameter and removes an element at the specified index. Following is the ... Read More

10K+ Views
In Java, the ArrayList class provides various built-in methods to remove all or a single element from it. Once those methods are called on the ArrayList, the list will become empty (). You can verify this using the size() method; it returns 0, if the list is empty. We can remove all the elements of an ArrayList in Java: Using clear() Method of List Interface Using removeAll() Method Removing all ArrayList Elements using clear() Method The clear() method of the List interface removes (deletes) all the elements from a list. ... Read More

22K+ Views
A list stores a sequence of elements of a similar type. Like an array, the elements in a List are stored at specific indices, starting from index 0. The 0th index indicates the "first element", the 1st indicates the "second" element, and so on. In Java, a list is represented by the interface named List (with the same name) that extends the Collection interface. To create a List object, we can instantiate any class that implements the List interface, such as ArrayList, Stack, Vector, etc (Since we cannot instantiate an interface). We can get the first element of the List in ... Read More

2K+ Views
In Java, an ArrayList is a class of the List interface, which stores elements of similar data types and can be null while creating. A sub-list is the view of a portion (or part) of an ArrayList. For example, if the given array list is {1, 2, 3, 4, 5}, then the possible sub-lists can be {1, 2}, {1, 2, 3}, {2, 3, 4}, {4, 5}, etc.The List interface in Java provides a built-in method named subList(), which directly returns a sub-list from the given ArrayList. Sublist from an ArrayList using the subList() Method The subList() method of the List interface returns a portion ... Read More

24K+ Views
In Java, a List is an interface that extends the Collection interface and represents a sequence of elements. Since the List is an interface. To create a List object, we need to instantiate a class that implements the List interface, such as ArrayList. The List provides various methods that help to check or find the element in it. We will discuss those methods in the coming section with suitable examples. Below is a list of various ways to find an element in the Java List: Using the get() Method Using ... Read More

1K+ Views
In Java, a List is an interface that represents an ordered collection of elements of the same type. You cannot directly create an object of the List interface, instead, you need to instantiate an ArrayList class or another class that implements the List interface.An array is a container that holds a fixed size of similar types of data. As the size is fixed, it can not be changed once created.The conversion between List and array is important because array provides faster access to the elements than List interface (faster in case of searching elements), and provides a fixed size of ... Read More

659 Views
In Java, an array is a container object that holds a similar type of data (elements), but has a fixed size. You can declare it by assigning values in curly braces or creating it using the new keyword by specifying the size. A List in Java is an interface that represents a sequence of elements of the same type (duplicates are allowed) and has a dynamic size. To create an object of the List interface, you can use one of its classes, such as ArrayList, Stack, Vector, etc.Converting an Array to a List in JavaSometimes we need to insert more data ... Read More