Mahesh Parahar has Published 255 Articles

How to remove element from ArrayList in Java?

Mahesh Parahar

Mahesh Parahar

Updated on 26-May-2022 13:18:03

320 Views

The List interface is a member of Java Collections Framework. It extends Collection and stores a sequence of elements. ArrayList and LinkedList are the most commonly used implementations of List interface. List provides user a precise control over where an element to be inserted in the List. These elements can ... Read More

How to remove all elements of ArrayList in Java?

Mahesh Parahar

Mahesh Parahar

Updated on 26-May-2022 13:17:24

8K+ Views

The List interface extends Collection interface and stores a sequence of elements. The List interface provides two methods to efficiently insert and remove multiple elements at an arbitrary point in the list. Unlike sets, list allows duplicate elements, allows multiple null values if null value is allowed in the list. ... Read More

How to get the first element of the List in Java?

Mahesh Parahar

Mahesh Parahar

Updated on 26-May-2022 13:15:35

16K+ Views

The List interface extends Collection interface. It is a collection that stores a sequence of elements. ArrayList is the most popular implementation of the List interface. User of a list has quite precise control over where an element to be inserted in the List. These elements are accessible by their ... Read More

How to get Sublist of an ArrayList using Java?

Mahesh Parahar

Mahesh Parahar

Updated on 26-May-2022 13:14:54

1K+ Views

The List interface is a Collection and it stores a sequence of elements. ArrayList is the most popular implementation of the List interface. A list provides user has quite precise control over where an element to be inserted in the List. These elements are accessible by their index and are ... Read More

How to find an element in a List with Java?

Mahesh Parahar

Mahesh Parahar

Updated on 26-May-2022 13:14:11

15K+ Views

The List interface extends Collection interface and represents a collection storing a sequence of elements. 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. ArrayList is the most popular implementation of ... Read More

How to convert between List and Array in Java?

Mahesh Parahar

Mahesh Parahar

Updated on 26-May-2022 13:11:47

697 Views

The List interface is a Collection and it stores a sequence of elements. ArrayList is the most popular implementation of the List interface. A list provides user has quite precise control over where an element to be inserted in the List. These elements are accessible by their index and are ... Read More

How to convert an Array to a List in Java Program?

Mahesh Parahar

Mahesh Parahar

Updated on 10-May-2022 09:01:24

224 Views

An array can be converted to a List easily using multiple ways.Way #1Create an empty list. Iterate through array and add each item to list using its add method.for (int i = 0; i < array.length; i++) { list.add(array[i]); }Way #2Use Arrays.asList() method to get a list ... Read More

How to check if ArrayList contains an item in Java?

Mahesh Parahar

Mahesh Parahar

Updated on 10-May-2022 08:52:42

4K+ Views

You can utilize contains() method of the List interface to check if an object is present in the list.contains() methodboolean contains(Object o)Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? ... Read More

How does a list work in Java?

Mahesh Parahar

Mahesh Parahar

Updated on 10-May-2022 08:42:04

121 Views

public interface List extends CollectionThe List interface extends Collection and declares the behavior of a collection that stores a sequence of elements.Elements can be inserted or accessed by their position in the list, using a zero-based index.A list may contain duplicate elements.In addition to the methods defined by Collection, List ... Read More

How do you turn an ArrayList into a Set in Java?

Mahesh Parahar

Mahesh Parahar

Updated on 10-May-2022 08:37:48

8K+ Views

An ArrayList can be converted to a set object using Set constructor. The resultant set will elliminate any duplicate entry present in the list and will contains only the unique values.Set set = new HashSet(list);Or we can use set.addAll() method to add all the elements of the list to the ... Read More

Advertisements