Example usage for java.util Arrays asList

List of usage examples for java.util Arrays asList

Introduction

In this page you can find the example usage for java.util Arrays asList.

Prototype

@SafeVarargs
@SuppressWarnings("varargs")
public static <T> List<T> asList(T... a) 

Source Link

Document

Returns a fixed-size list backed by the specified array.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] strArray = new String[] { "z", "a", "A" };
    List list = Arrays.asList(strArray);

    Collections.sort(list);//from  w  w w  . j  ava 2 s. c  o  m

    Collections.sort(list, String.CASE_INSENSITIVE_ORDER);

    Collections.sort(list, Collections.reverseOrder());

    Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
    Collections.reverse(list);
}

From source file:Main.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    HashSet<String> set = new HashSet<String>(Arrays.asList(elements));

    Object[] arrObj = set.toArray();

    for (int i = 0; i < arrObj.length; i++) {
        System.out.println(arrObj[i]);
    }//from ww w.ja v  a 2s. co  m

    System.out.println(set);
}

From source file:Main.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    Set<String> set = new HashSet<String>(Arrays.asList(elements));

    elements = new String[] { "E", "F" };

    set.addAll(Arrays.asList(elements));

    System.out.println(set);//from   w  w  w  .j a va2  s  . co  m

    set.clear();

    System.out.println(set);
}

From source file:Main.java

public static void main(String args[]) {
    String elements[] = { "I", "P", "E", "G", "P" };
    Set set = new HashSet(Arrays.asList(elements));
    Iterator iter = set.iterator();
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }/*from w w w .  j  a v a 2 s.c  o  m*/
}

From source file:Main.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    HashSet<String> set = new HashSet<String>(Arrays.asList(elements));

    elements = new String[] { "E", "F" };

    set.addAll(Arrays.asList(elements));

    System.out.println(set);/*from  w  w w  . j a  va2s .c  om*/

    set.clear();

    System.out.println(set);
}

From source file:Sort.java

public static void main(String args[]) {
    String[] strArray = new String[] { "Java", "Source", "And", "and", "Support", "java2s" };

    List l = Arrays.asList(strArray);
    Collections.sort(l);//from  w w  w  .j a va2 s  .  co m
    System.out.println(l);
}

From source file:MainClass.java

License:asdf

public static void main(String[] args) {
    String[] sa = new String[] { "adf", "fdsa", "ASDF", "FSA", "r", "R" };

    System.out.println("Before sorting: " + Arrays.asList(sa));
    Arrays.sort(sa, new AlphabeticComparator());
    System.out.println("After sorting: " + Arrays.asList(sa));
}

From source file:MainClass.java

public static void main(String args[]) {
    String s[] = { "A", "B", "C", "D", "E", "H", "I" };
    List list1 = Arrays.asList(s);
    List list2 = Arrays.asList(s);
    Random rand = new Random(100);
    Collections.shuffle(list1, rand);
    Collections.shuffle(list2, rand);
    System.out.println(list1);//from   ww w.  ja v  a  2s .  co  m
    System.out.println(list2);
}

From source file:Shuffle.java

public static void main(String args[]) {
    String[] strArray = new String[] { "Java", "Source", "And", "and", "Support", "java2s" };

    List l = Arrays.asList(strArray);
    Collections.shuffle(l);/*  w w  w.j a  va2 s  .  c  o  m*/
    System.out.println(l);
}

From source file:Main.java

public static void main(String[] args) {
    String[] alphabets = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" };

    List<String> list = Arrays.asList(alphabets);

    Collections.shuffle(list);/*w  w  w .j a v a 2s .  c o m*/

    for (String alpha : list) {
        System.out.print(alpha + " ");
    }
}