Java List.add(E e)

Syntax

List.add(E e) has the following syntax.

boolean add(E e)

Example

In the following code shows how to use List.add(E e) method.


import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/*from  w ww .  j av a 2s .co m*/
public class Main {

  public static void main(String[] args) {
    List<String> myList = new ArrayList<String>();
    myList.add("Hello");
    myList.add(0,"World");
    myList.add("java2s.com");
    Set<String> set = new HashSet<String>(myList);

    System.out.println(set);
  }

}

The code above generates the following result.