List of usage examples for java.util ArrayList ArrayList
public ArrayList(Collection<? extends E> c)
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Content.class); List<String> strings = new ArrayList<String>(2); strings.add("foo"); strings.add("bar"); Content content = new Content(); content.setKeywords(strings);// w w w.j a v a 2 s . c o m Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(content, System.out); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("ArrayListComboBoxModel"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Collection<Object> col = System.getProperties().values(); ArrayList<Object> arrayList = new ArrayList<Object>(col); ArrayListComboBoxModel model = new ArrayListComboBoxModel(arrayList); JComboBox comboBox = new JComboBox(model); frame.add(comboBox, BorderLayout.NORTH); frame.setSize(300, 225);/*from w ww .ja v a 2 s. c o m*/ frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { ArrayList myList = new ArrayList(5); for (int i = 0; i < 5; i++) { myList.add(new Integer(i)); }/* w w w . j a va 2s . c o m*/ System.out.println("List contains " + myList.size() + " elements"); Integer int2 = new Integer(2); System.out.println("List contains Integer(2): " + myList.contains(int2)); System.out.println("Integer(2) is at index " + myList.indexOf(int2)); myList.set(2, new Integer(99)); System.out.println("Get element at index 2: " + myList.get(2)); myList.ensureCapacity(15); for (int i = 10; i < 15; i++) { myList.add(new Integer(i)); } myList.subList(10, 15).clear(); myList.trimToSize(); System.out.println(myList); }
From source file:Main.java
public static void main(String[] a) { Map<String, String> yourMap = new HashMap<String, String>(); yourMap.put("1", "one"); yourMap.put("2", "two"); yourMap.put("3", "three"); Map<String, Object> map = new LinkedHashMap<String, Object>(); List<String> keyList = new ArrayList<String>(yourMap.keySet()); List<String> valueList = new ArrayList<String>(yourMap.values()); Set<String> sortedSet = new TreeSet<String>(valueList); Object[] sortedArray = sortedSet.toArray(); int size = sortedArray.length; for (int i = 0; i < size; i++) { map.put(keyList.get(valueList.indexOf(sortedArray[i])), sortedArray[i]); }/*from w w w. ja v a2 s. c o m*/ Set ref = map.keySet(); Iterator it = ref.iterator(); while (it.hasNext()) { String i = (String) it.next(); System.out.println(i); } }
From source file:Main.java
public static void main(String[] args) throws InterruptedException, ExecutionException { List<String> searchList = new ArrayList<String>(7); searchList.add("hello"); searchList.add("world"); searchList.add("CSS"); searchList.add("debian"); searchList.add("linux"); searchList.add("HTML"); searchList.add("stack"); Set<String> targetSet = new HashSet<String>(searchList); Set<String> matchSet = findMatches(searchList, targetSet); for (String match : matchSet) { System.out.println("match: " + match); }/*from w w w .j a v a 2 s. c o m*/ }
From source file:Main.java
public static void main(final String[] args) throws Exception { Random RND = new Random(); ExecutorService es = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); List<Future<String>> results = new ArrayList<>(10); for (int i = 0; i < 10; i++) { results.add(es.submit(new TimeSliceTask(RND.nextInt(10), TimeUnit.SECONDS))); }//from w ww. j a va 2 s . co m es.shutdown(); while (!results.isEmpty()) { Iterator<Future<String>> i = results.iterator(); while (i.hasNext()) { Future<String> f = i.next(); if (f.isDone()) { System.out.println(f.get()); i.remove(); } } } }
From source file:Main.java
public static void main(String[] args) { Map<String, Student> map = new HashMap<>(); map.put("s1", new Student(5, "A")); map.put("s2", new Student(4, "B")); map.put("s3", new Student(10, "C")); map.put("s4", new Student(2, "D")); Collection<Student> students = map.values(); List<Student> list = new ArrayList<>(students); Collections.sort(list, new MyComparator()); for (Iterator<Student> it = list.iterator(); it.hasNext();) { Student stdn = (Student) it.next(); System.out.println("Student id : " + stdn.id); System.out.println("Student Name : " + stdn.name); }//w w w .j av a 2 s .com }
From source file:Main.java
public static void main(String[] args) { List<Person> roster = createRoster(); System.out.println("Members by gender:"); Map<Person.Sex, List<Person>> byGender = roster.stream().collect(Collectors.groupingBy(Person::getGender)); List<Map.Entry<Person.Sex, List<Person>>> byGenderList = new ArrayList<>(byGender.entrySet()); byGenderList.stream().forEach(e -> { System.out.println("Gender: " + e.getKey()); e.getValue().stream().map(Person::getName).forEach(f -> System.out.println(f)); });// www. j a v a 2s . c o m }
From source file:Main.java
public static void main(String[] args) { List<Person> roster = createRoster(); ConcurrentMap<Person.Sex, List<Person>> byGenderParallel = roster.parallelStream() .collect(Collectors.groupingByConcurrent(Person::getGender)); List<Map.Entry<Person.Sex, List<Person>>> byGenderList = new ArrayList<>(byGenderParallel.entrySet()); System.out.println("Group members by gender:"); byGenderList.stream().forEach(e -> { System.out.println("Gender: " + e.getKey()); e.getValue().stream().map(Person::getName).forEach(f -> System.out.println(f)); });//from w w w . j av a2 s . c o m }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addRow(new Object[] { "r1" }); model.addRow(new Object[] { "r2" }); model.addRow(new Object[] { "r3" }); Vector data = model.getDataVector(); Vector row = (Vector) data.elementAt(1); int mColIndex = 0; List colData = new ArrayList(table.getRowCount()); for (int i = 0; i < table.getRowCount(); i++) { row = (Vector) data.elementAt(i); colData.add(row.get(mColIndex)); }/* www.jav a2s. c o m*/ // Append a new column with copied data model.addColumn("Col3", colData.toArray()); JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.setVisible(true); }