Home » Core Java » util » List


Java List Remove Object Example

In this example we will discuss how to remove objects from a java.util.List. There are 2 methods described in the Java API to do so : E remove(int index) We can use index of list to remove the object. boolean remove(Object o)   We can pass the object itself which needs to be removed. For this method to work for ...

Read More »

Java List to Array Example

In this example, we will see how to convert a List (java.util.List) in Java into an array. java.util.List has two methods to do so : T[] toArray(T[] a) – returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified ...

Read More »

Java List Contains Method Example

In this example we will discuss the java.util.List.contains method and see how to use it. The method signature in the Java interface List is : boolean contains(Object o). As per the Java documentation, it returns true if and only if this list contains at least one element’s equals method returns true for object which we are searching for. Lets see ...

Read More »

Java Array to List Example

In this example I will show you how to convert an array into a java.util.List. We will use the java.util.Arrays class to convert an Object Array into a List of Objects. Lets see the example: 1) Object Array to List. A List can only store objects and not the primitives. So, lets how we can convert an array of objects into ...

Read More »

Sorted List Java Example

In this article, we will create a Java example on Sorted List. I will show how to sort a java.util.List using methods of java.util.Collections class. 1. SimpleSortExample Create a Java class called SimpleSortExample with the following source code. SimpleSortExample.java 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 ...

Read More »