List: add(T e) : List « java.util « Java by API






List: add(T e)

  
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {

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

    System.out.println(set);
  }

}

   
    
  








Related examples in the same category

1.List: addAll(Collection c)
2.List: clear()
3.List: clone()
4.List: contains(Object o)
5.List: equals(Object o)
6.List: get(int index)
7.List: isEmpty()
8.List: iterator()
9.List: lastIndexOf(Object o)
10.List: listIterator()
11.List: remove(int index)
12.List: remove(Object o)
13.List: removeAll(Collection c)
14.List: retainAll(Collection c)
15.List: set(int index, T element)
16.List: subList(int fromIndex, int toIndex)
17.List: toArray(T[] a)