List of usage examples for java.util List add
boolean add(E e);
From source file:Main.java
public static void main(String args[]) { // create link list object List<Integer> list = new LinkedList<Integer>(); // populate the list list.add(-8); list.add(4);/*from ww w. j a va 2 s .co m*/ list.add(-5); list.add(2); // comparing using natural ordering System.out.println("Min val: " + Collections.min(list)); System.out.println("Min val: " + Collections.min(list, Collections.reverseOrder())); }
From source file:Main.java
public static void main(String[] argv) throws Exception { List<Integer> list = new ArrayList<Integer>(); for (int i = 1; i <= 12; i++) list.add(new Integer(i)); Collections.shuffle(list);//from w w w . jav a2 s. c o m System.out.println(list); }
From source file:Main.java
public static void main(String[] args) { // create vector List<String> vector = new Vector<String>(); // populate the vector vector.add("R"); vector.add("B"); vector.add("R"); vector.add("java2s.com"); System.out.println("Initial values are :" + vector); Collections.replaceAll(vector, "R", "java2s.com"); System.out.println("Value after replace :" + vector); }
From source file:Main.java
public static void main(String[] args) throws Exception { Path path = Paths.get("C:\\Java_Dev\\test1.txt"); AclFileAttributeView aclView = Files.getFileAttributeView(path, AclFileAttributeView.class); if (aclView == null) { System.out.format("ACL view is not supported.%n"); return;// w ww . j ava 2 s .c o m } UserPrincipal bRiceUser = FileSystems.getDefault().getUserPrincipalLookupService() .lookupPrincipalByName("brice"); Set<AclEntryPermission> permissions = EnumSet.of(AclEntryPermission.READ_DATA, AclEntryPermission.WRITE_DATA); AclEntry.Builder builder = AclEntry.newBuilder(); builder.setPrincipal(bRiceUser); builder.setType(AclEntryType.ALLOW); builder.setPermissions(permissions); AclEntry newEntry = builder.build(); List<AclEntry> aclEntries = aclView.getAcl(); aclEntries.add(newEntry); aclView.setAcl(aclEntries); }
From source file:Main.java
public static void main(String args[]) { // create link list object List<Integer> list = new LinkedList<Integer>(); // populate the list list.add(-8); list.add(4);/*from ww w .j a va2 s. co m*/ list.add(-5); list.add(2); // comparing using natural ordering System.out.println("Max val: " + Collections.max(list)); System.out.println("Max val: " + Collections.max(list, Collections.reverseOrder())); }
From source file:com.apextom.util.CollectionUtil.java
public static void main(String[] args) { List<Object> list = new ArrayList<Object>(); list.add("aa"); list.add(null);/*from www . j a v a2 s.c o m*/ list.add(null); System.out.println(list); removeNull(list); System.out.println(list); }
From source file:Main.java
public static void main(String[] args) { List<String> syncList = Collections.synchronizedList(new ArrayList<String>()); syncList.add("one"); syncList.add("two"); syncList.add("three"); synchronized (syncList) { Iterator<String> iterator = syncList.iterator(); while (iterator.hasNext()) { System.out.println("item: " + iterator.next()); }/* w ww. ja v a 2 s. c om*/ } }
From source file:Main.java
public static void main(String args[]) { // create Linked List List<Integer> list = new LinkedList<Integer>(); // populate list list.add(5); list.add(2);/*w ww .j a v a2 s . c om*/ list.add(1); list.add(-3); System.out.println("List before shuffle: " + list); // shuffle the list Collections.shuffle(list, new Random()); System.out.println("List after shuffle: " + list); }
From source file:it.avalz.opendaylight.controller.examples.JsonParser.java
public static void main(String[] args) { String s = "{\"ids\":[\"00:00:00:00:00:00:00:01\", \"00:00:00:00:00:00:00:02\"], \"width\":200, \"height\":100}"; JSONObject json = null;/*from ww w. java2 s . c om*/ try { json = (JSONObject) new JSONParser().parse(s); } catch (ParseException ex) { ex.printStackTrace(); } System.out.println(json.get("ids")); JSONArray array = (JSONArray) json.get("ids"); System.out.println(array.get(0)); System.out.println(json.get("width")); System.out.println(json.get("height")); List<String> l = new ArrayList<String>(); l.add("\"DROP\""); l.add("\"OUTPUT=2\""); System.out.println(l); }
From source file:Main.java
public static void main(String args[]) { // create array list object List<String> arrlist = new ArrayList<String>(); // populate the list arrlist.add("A"); arrlist.add("B"); arrlist.add("from java2s.com"); System.out.println("Initial collection: " + arrlist); // shuffle the list Collections.shuffle(arrlist); System.out.println("Final collection after shuffle: " + arrlist); }