List of usage examples for java.util ArrayList add
public boolean add(E e)
From source file:Main.java
public static void main(String[] args) { ArrayList<String> aList = new ArrayList<String>(); aList.add("1"); aList.add("2"); aList.add("3"); aList.add("4"); aList.add("5"); for (String str : aList) { System.out.println(str);/*ww w .j a v a 2 s .c om*/ } Iterator itr = aList.iterator(); // remove 2 from ArrayList using Iterator's remove method. String strElement = ""; while (itr.hasNext()) { strElement = (String) itr.next(); if (strElement.equals("2")) { itr.remove(); break; } } for (String str : aList) { System.out.println(str); } }
From source file:Main.java
public static void main(String[] args) { ArrayList<Integer> arrlist = new ArrayList<Integer>(); arrlist.add(20); arrlist.add(25);//from w w w . j a va 2 s .co m arrlist.add(10); arrlist.add(15); System.out.println(arrlist); // list contains element 10 boolean retval = arrlist.contains(10); if (retval == true) { System.out.println("element 10 is contained in the list"); } else { System.out.println("element 10 is not contained in the list"); } // list does not contain element 30 boolean retval2 = arrlist.contains(30); if (retval2 == true) { System.out.println("element 30 is contained in the list"); } else { System.out.println("element 30 is not contained in the list"); } }
From source file:IteratorDemo.java
public static void main(String args[]) { ArrayList<String> al = new ArrayList<String>(); al.add("C"); al.add("A");/*from w w w. j ava2 s . c o m*/ al.add("E"); al.add("B"); al.add("D"); al.add("F"); Iterator<String> itr = al.iterator(); while (itr.hasNext()) { String element = itr.next(); System.out.print(element + " "); } ListIterator<String> litr = al.listIterator(); while (litr.hasNext()) { String element = litr.next(); litr.set(element + "+"); } itr = al.iterator(); while (itr.hasNext()) { String element = itr.next(); System.out.print(element + " "); } while (litr.hasPrevious()) { String element = litr.previous(); System.out.print(element + " "); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_5); document.open();// w w w . j a v a2 s.c o m PdfContentByte cb = writer.getDirectContent(); PdfLayer radiogroup = PdfLayer.createTitle("Radio Group", writer); PdfLayer radio1 = new PdfLayer("Radiogroup: layer 1", writer); radio1.setOn(true); PdfLayer radio2 = new PdfLayer("Radiogroup: layer 2", writer); radio2.setOn(false); PdfLayer radio3 = new PdfLayer("Radiogroup: layer 3", writer); radio3.setOn(false); radiogroup.addChild(radio1); radiogroup.addChild(radio2); radiogroup.addChild(radio3); ArrayList options = new ArrayList(); options.add(radio1); options.add(radio2); options.add(radio3); writer.addOCGRadioGroup(options); cb.beginLayer(radio1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("option 1"), 50, 600, 0); cb.endLayer(); cb.beginLayer(radio2); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("option 2"), 50, 575, 0); cb.endLayer(); cb.beginLayer(radio3); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("option 3"), 50, 550, 0); cb.endLayer(); document.close(); }
From source file:ArrayListComboBoxModel.java
public static void main(String args[]) { JFrame frame = new JFrame("ArrayListComboBoxModel"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ArrayList<Object> arrayList = new ArrayList<Object>(); arrayList.add("A"); arrayList.add("B"); arrayList.add("C"); ArrayListComboBoxModel model = new ArrayListComboBoxModel(arrayList); JComboBox comboBox = new JComboBox(model); frame.add(comboBox, BorderLayout.NORTH); frame.setSize(300, 225);/*w w w .j a va 2s. c o m*/ frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { ArrayList<String> al = new ArrayList<String>(); al.add("C"); al.add("A");/* w w w. ja va 2 s . com*/ al.add("E"); al.add("B"); al.add("D"); al.add("F"); System.out.print("Original contents of al: "); Iterator<String> itr = al.iterator(); while (itr.hasNext()) { String element = itr.next(); System.out.print(element + " "); } System.out.println(); ListIterator<String> litr = al.listIterator(); while (litr.hasNext()) { String element = litr.next(); litr.set(element + "+"); } // Now, display the list backwards. System.out.print("Modified list backwards: "); while (litr.hasPrevious()) { String element = litr.previous(); System.out.print(element + " "); } }
From source file:contractEditor.SPConfFileEditor.java
public static void main(String[] args) { JSONObject obj = new JSONObject(); ArrayList fileList = new ArrayList(); fileList.add("confSP" + File.separator + "HOST1.json"); fileList.add("confSP" + File.separator + "HOST2.json"); fileList.add("confSP" + File.separator + "HOST3.json"); fileList.add("confSP" + File.separator + "HOST4.json"); obj.put("contract_list_of_SP", fileList); try {/*w ww.j a va 2s. c o m*/ FileWriter file = new FileWriter("confSP" + File.separator + "contractFileList.json"); file.write(obj.toJSONString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } System.out.print(obj); }
From source file:MainClass.java
public static void main(String[] av) { String[] stringArray = new String[] { "c", "e", "a", "k" }; ArrayList<String> list = new ArrayList<String>(); for (String s : stringArray) { list.add(s); }// w ww. j av a 2 s . co m Collections.sort(list, String.CASE_INSENSITIVE_ORDER); for (String s : list) { System.out.println(s); } }
From source file:MainClass.java
public static void main(String[] a) { ArrayList<Employee> emps = new ArrayList<Employee>(); emps.add(new Employee("A", "G")); emps.add(new Employee("T", "A")); emps.add(new Employee("K", "J")); System.out.println(emps);//from w ww .j a v a2 s . c om Employee e = emps.get(1); e.setLastName("new"); System.out.println(emps); }
From source file:Main.java
public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(); list.add("Monday"); list.add("Tuesdag"); list.add("Wednesday"); list.add("Thursday"); list.add("Friday"); list.add("Saturday"); list.add("Sunday"); Iterator<String> iterator = null; iterator = list.iterator();/* ww w . j a v a2 s. c o m*/ while (iterator.hasNext()) { String element = iterator.next(); System.out.println(element); } for (iterator = list.iterator(); iterator.hasNext();) { String element = iterator.next(); System.out.println(element); } for (String element : list) { System.out.println(element); } }