Home » Core Java » util » List

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 java.util.List into an array. java.util.List has 2 methods to do so : T[] toArray(T[] a) Object[] toArray() Both these methods return an array containing all of the elements in this list in proper sequence. The difference between the two methods, as we can see in the method signature, is that List.toArray() ...

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 »

Java Sorted List Example

In this example, I will show how to sort a java.util.List using methods of java.util.Collections class. SimpleSortExample Create a Java class called SimpleSortExample with the following source code.         package com.javacodegeeks.example; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class SimpleSortExample { public static void main(String[] args) { List list = new ArrayList(); for (int i=0;i<10;i++) { list.add((int) ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns