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) { List<Person> roster = createRoster(); System.out.println("Total age by gender:"); Map<Person.Sex, Integer> totalAgeByGender = roster.stream().collect( Collectors.groupingBy(Person::getGender, Collectors.reducing(0, Person::getAge, Integer::sum))); List<Map.Entry<Person.Sex, Integer>> totalAgeByGenderList = new ArrayList<>(totalAgeByGender.entrySet()); totalAgeByGenderList.stream()/*from w w w . j a v a2 s. co m*/ .forEach(e -> System.out.println("Gender: " + e.getKey() + ", Total Age: " + e.getValue())); }
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); // Copy the first column 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)); }//ww w. java2 s . co m JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { List<Person> roster = createRoster(); System.out.println("Names by gender:"); Map<Person.Sex, List<String>> namesByGender = roster.stream().collect( Collectors.groupingBy(Person::getGender, Collectors.mapping(Person::getName, Collectors.toList()))); List<Map.Entry<Person.Sex, List<String>>> namesByGenderList = new ArrayList<>(namesByGender.entrySet()); namesByGenderList.stream().forEach(e -> { System.out.println("Gender: " + e.getKey()); e.getValue().stream().forEach(f -> System.out.println(f)); });/* w w w. j av a 2 s . com*/ }
From source file:EmpComparator.java
public static void main(String args[]) { String names[] = { "Bart", "Hugo", "Lisa", "Marge", "Homer", "Maggie", "Roy" }; // Convert to list List list = new ArrayList(Arrays.asList(names)); // Ensure list sorted Collections.sort(list);//from ww w . ja va 2s . c o m System.out.println("Sorted list: [length: " + list.size() + "]"); System.out.println(list); // Search for element in list int index = Collections.binarySearch(list, "Maggie"); System.out.println("Found Maggie @ " + index); // Search for element not in list index = Collections.binarySearch(list, "Jimbo Jones"); System.out.println("Didn't find Jimbo Jones @ " + index); // Insert int newIndex = -index - 1; list.add(newIndex, "Jimbo Jones"); System.out.println("With Jimbo Jones added: [length: " + list.size() + "]"); System.out.println(list); // Min should be Bart System.out.println(Collections.min(list)); // Max should be Roy System.out.println(Collections.max(list)); Comparator comp = Collections.reverseOrder(); // Reversed Min should be Roy System.out.println(Collections.min(list, comp)); // Reversed Max should be Bart System.out.println(Collections.max(list, comp)); }
From source file:MyComparator.java
public static void main(String[] args) { TreeMap tm = new TreeMap(); tm.put(1, new Double(344.34)); tm.put(0, new Double(123.22)); tm.put(4, new Double(138.00)); tm.put(2, new Double(919.22)); tm.put(3, new Double(-119.08)); List<Map.Entry> valueList = new ArrayList(tm.entrySet()); Collections.sort(valueList, new MyComparator()); Iterator<Map.Entry> iterator = valueList.iterator(); while (iterator.hasNext()) { Map.Entry entry = iterator.next(); System.out.println("Value: " + entry.getValue()); }//from w w w . ja va 2s . c om }
From source file:LogTest.java
public static void main(String[] args) throws IOException { String inputfile = args[0];/* w ww .j a va 2 s . c om*/ String outputfile = args[1]; Map<String, Integer> map = new TreeMap<String, Integer>(); Scanner scanner = new Scanner(new File(inputfile)); while (scanner.hasNext()) { String word = scanner.next(); Integer count = map.get(word); count = (count == null ? 1 : count + 1); map.put(word, count); } scanner.close(); List<String> keys = new ArrayList<String>(map.keySet()); Collections.sort(keys); PrintWriter out = new PrintWriter(new FileWriter(outputfile)); for (String key : keys) out.println(key + " : " + map.get(key)); out.close(); }
From source file:postenergy.PostHttpClient.java
public static void main(String[] args) { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://iplant.dk/addData.php?n=mindass"); try {/* w w w . ja v a2 s . c om*/ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("?n", "=mindass")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { System.out.println(line); if (line.startsWith("Input:")) { String key = line.substring(6); // do something with the key System.out.println("key:" + key); } } } catch (IOException e) { System.out.println("There was an error: " + e); } }
From source file:ArrayListComboBoxModel.java
public static void main(String args[]) { JFrame frame = new JFrame("ArrayListComboBoxModel"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Collection col = System.getProperties().values(); ArrayList arrayList = new ArrayList(col); ArrayListComboBoxModel model = new ArrayListComboBoxModel(arrayList); JComboBox comboBox = new JComboBox(model); Container contentPane = frame.getContentPane(); contentPane.add(comboBox, BorderLayout.NORTH); frame.setSize(300, 225);/*from ww w. j a v a 2 s .c o m*/ frame.setVisible(true); }
From source file:com.sm.replica.TestRClient.java
public static void main(String[] args) { int i = 10;//from w w w. j a v a 2s. c om List<String> list = new ArrayList<String>(i); for (int j = 0; j < i; j++) list.add(null); logger.info("freq " + list.size()); String logPath = "/Users/mhsieh/java/open/voldemort-0.81/config/addon-1/data/log"; String store = "test"; CacheStore trxLog = new CacheStore(logPath, null, 0, store, false); ReplicaClient client = new NTReplicaClient("localhost:6910", store, trxLog, logPath); new Thread(client).start(); }
From source file:main.StratioENEI.java
/** * @param args the command line arguments *//* w w w . j a v a 2s .c o m*/ public static void main(String[] args) throws IOException { // TODO code application logic here float[][] custos; List<String> ordem; List<String> cidades; float custoTotal; int nCidades = Integer.parseInt(args[0]); String cidadeInicial = args[1]; String cidadeFinal = args[2]; for (Mode m : Mode.values()) { custos = new float[nCidades][nCidades]; cidades = new ArrayList<>(nCidades); ordem = new ArrayList<>(nCidades); readFromCSV(m.file, custos, cidades); custoTotal = calculate(custos, cidades.indexOf(cidadeInicial), cidades.indexOf(cidadeFinal), ordem); printRota(custoTotal, cidadeInicial, cidadeFinal, cidades, ordem, m); } }