List.add(int index, E element) has the following syntax.
void add(int index, E element)
In the following code shows how to use List.add(int index, E element) method.
import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; //from w w w .j a v a 2 s . c o 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.