List of usage examples for java.util Arrays asList
@SafeVarargs @SuppressWarnings("varargs") public static <T> List<T> asList(T... a)
From source file:Main.java
public static void main(String args[]) { String init[] = { "One", "Two", "Three", "One", "from java2s.com", "Three" }; // create one list List<String> list = new ArrayList<String>(Arrays.asList(init)); System.out.println("List value before: " + list); // sort the list Collections.sort(list);//from ww w .j a v a 2 s . c om System.out.println("List value after sort: " + list); }
From source file:Main.java
public static void main(String[] args) { List<String> times = Arrays.asList(new String[] { "03:00 AM", "12:30 PM", "16:15" }); Collections.sort(times, new TimeStringComparator()); System.out.println(times);/* w w w . j a v a2 s. c om*/ }
From source file:MainClass.java
public static void main(String args[]) { String orig[] = { "I", "P", "E", "G", "P" }; String act[] = { "P", "P", "S" }; Set origSet = new HashSet(Arrays.asList(orig)); List actList = Arrays.asList(act); System.out.println(origSet.removeAll(actList)); System.out.println(origSet);/*from w w w . j a v a 2s .c o m*/ }
From source file:SaveVector1.java
public static void main(String args[]) throws Exception { Vector v = new Vector(Arrays.asList(args)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(v);/*from w ww. jav a2 s . co m*/ oos.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); Vector v2 = (Vector) ois.readObject(); Enumeration e = v.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } }
From source file:Main.java
public static void main(final String[] args) { final Set<String[]> s = new HashSet<String[]>(); final Set<List<String>> s2 = new HashSet<List<String>>(); s.add(new String[] { "lucy", "simon" }); s2.add(Arrays.asList(new String[] { "lucy", "simon" })); System.out.println(s.contains(new String[] { "lucy", "simon" })); // false System.out.println(s2.contains(Arrays.asList(new String[] { "lucy", "simon" }))); // true }
From source file:SplitDemo.java
public static void main(String[] args) { String input = "This!!unusual use!!of exclamation!!points"; System.out.println(Arrays.asList(Pattern.compile("!!").split(input))); // Only do the first three: System.out.println(Arrays.asList(Pattern.compile("!!").split(input, 3))); System.out.println(Arrays.asList("Aha! String has a split() built in!".split(" "))); }
From source file:Main.java
public static void main(String[] argv) throws Exception { List stuff = Arrays.asList(new String[] { "a", "b" }); List list = new ArrayList(stuff); List list2 = new LinkedList(list); Set set = new HashSet(stuff); Set set2 = new TreeSet(set); Map map = new HashMap(); Map map2 = new TreeMap(map); }
From source file:Main.java
public static void main(String[] args) { Integer[] intArray = { 1, 2, 3, 4, 5, 6, 7, 8 }; List<Integer> listOfIntegers = new ArrayList<>(Arrays.asList(intArray)); List<Integer> serialStorage = new ArrayList<>(); System.out.println("Serial stream:"); listOfIntegers.stream()//from ww w .jav a 2 s . c o m // Don't do this! It uses a stateful lambda expression. .map(e -> { serialStorage.add(e); return e; }) .forEachOrdered(e -> System.out.print(e + " ")); System.out.println(""); serialStorage.stream().forEachOrdered(e -> System.out.print(e + " ")); System.out.println(""); System.out.println("Parallel stream:"); List<Integer> parallelStorage = Collections.synchronizedList(new ArrayList<>()); listOfIntegers.parallelStream() // Don't do this! It uses a stateful lambda expression. .map(e -> { parallelStorage.add(e); return e; }) .forEachOrdered(e -> System.out.print(e + " ")); System.out.println(""); parallelStorage.stream().forEachOrdered(e -> System.out.print(e + " ")); System.out.println(""); }
From source file:MainClass.java
public static void main(String args[]) { String init[] = { "One", "Two", "Three", "One", "Two", "Three" }; List list1 = new ArrayList(Arrays.asList(init)); List list2 = new ArrayList(Arrays.asList(init)); list1.remove("One"); System.out.println(list1);/* ww w . j a va2s . c o m*/ list2.removeAll(Collections.singleton("One")); System.out.println(list2); }
From source file:StringSorting.java
public static void main(String[] args) { String[] sa = new String[] { "d", "e", "a", "c", "g" }; System.out.println("Before sorting: " + Arrays.asList(sa)); Arrays.sort(sa);// w w w .j ava 2 s . com System.out.println("After sorting: " + Arrays.asList(sa)); }