List of usage examples for java.util List get
E get(int index);
From source file:Main.java
public static void main(String[] args) { List<String> friends = Arrays.asList("A", "B", "C", "D"); //external iterate with index == evil for (int i = 0; i < friends.size(); i++) { System.out.println(friends.get(i)); }//w ww . j a va2s. co m //external iterate on collection, better but ... external for (String friend : friends) { System.out.println(friend); } //lambda friends.forEach(s -> System.out.println(s)); //lambda reference friends.forEach(System.out::println); }
From source file:org.seasar.dao.spring.example.EmployeeAutoDaoClient.java
public static void main(final String[] args) { final BeanFactoryLocator locator = ContextSingletonBeanFactoryLocator.getInstance(); final BeanFactoryReference ref = locator.useBeanFactory("context"); final ApplicationContext context = (ApplicationContext) ref.getFactory(); try {/* w w w . j a va 2 s . com*/ final EmployeeAutoDao dao = (EmployeeAutoDao) context.getBean("employeeAutoDao"); dao.getEmployeeByJobDeptno(null, null); dao.getEmployeeByJobDeptno("CLERK", null); dao.getEmployeeByJobDeptno(null, new Integer(20)); dao.getEmployeeByJobDeptno("CLERK", new Integer(20)); List employees = dao.getEmployeesBySal(0, 1000); for (int i = 0; i < employees.size(); ++i) { System.out.println(employees.get(i)); } employees = dao.getEmployeeByDname("SALES"); for (int i = 0; i < employees.size(); ++i) { System.out.println(employees.get(i)); } final EmployeeSearchCondition dto = new EmployeeSearchCondition(); dto.setDname("RESEARCH"); employees = dao.getEmployeesBySearchCondition(dto); for (int i = 0; i < employees.size(); ++i) { System.out.println(employees.get(i)); } final Employee employee = dao.getEmployeeByEmpno(7788); System.out.println("before timestamp:" + employee.getTimestamp()); dao.update(employee); System.out.println("after timestamp:" + employee.getTimestamp()); } finally { ref.release(); } }
From source file:Main.java
public static void main(String[] args) { Integer[] arr = { 1, 2, 3, 1, 4, 4, 1, 5 }; System.out.println(Arrays.toString(arr)); List<Integer> l = Arrays.asList(arr); System.out.println(l);//from w w w .ja v a 2 s . com Set<Integer> set = new HashSet<Integer>(); for (int j = 0; j < l.size(); j++) { if (Collections.frequency(l, l.get(j)) > 1) { set.add(l.get(j)); } } System.out.println("dups are:" + set); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { List list = Arrays.asList("a", "c", "b"); Collections.sort(list);//from ww w . j a va 2 s . c om for (int i = 0, n = list.size(); i < n; i++) { if (i != 0) System.out.print(", "); System.out.print(list.get(i)); } System.out.println(); }
From source file:drpc.KMeansDrpcQuery.java
public static void main(final String[] args) throws IOException, TException, DRPCExecutionException, DecoderException, ClassNotFoundException { if (args.length < 3) { System.err.println("Where are the arguments? args -- DrpcServer DrpcFunctionName folder"); return;//from w w w . jav a2 s . c o m } final DRPCClient client = new DRPCClient(args[0], 3772, 1000000 /*timeout*/); final Queue<String> featureFiles = new ArrayDeque<String>(); SpoutUtils.listFilesForFolder(new File(args[2]), featureFiles); Scanner scanner = new Scanner(featureFiles.peek()); int i = 0; while (scanner.hasNextLine() && i++ < 10) { List<Map<String, List<Double>>> dict = SpoutUtils.pythonDictToJava(scanner.nextLine()); for (Map<String, List<Double>> map : dict) { i++; Double[] features = map.get("chi2").toArray(new Double[0]); Double[] moreFeatures = map.get("chi1").toArray(new Double[0]); Double[] rmsd = map.get("rmsd").toArray(new Double[0]); Double[] both = (Double[]) ArrayUtils.addAll(features, moreFeatures); String parameters = serializeFeatureVector(ArrayUtils.toPrimitive(both)); String centroidsSerialized = runQuery(args[1], parameters, client); Gson gson = new Gson(); Object[] deserialized = gson.fromJson(centroidsSerialized, Object[].class); for (Object obj : deserialized) { // result we get is of the form List<result> List l = ((List) obj); centroidsSerialized = (String) l.get(0); String[] centroidSerializedArrays = centroidsSerialized .split(MlStormClustererQuery.KmeansClustererQuery.CENTROID_DELIM); List<double[]> centroids = new ArrayList<double[]>(); for (String centroid : centroidSerializedArrays) { centroids.add(MlStormFeatureVectorUtils.deserializeToFeatureVector(centroid)); } double[] rmsdPrimitive = ArrayUtils.toPrimitive(both); double[] rmsdKmeans = new double[centroids.size()]; for (int k = 0; k < centroids.size(); k++) { System.out.println("centroid -- " + Arrays.toString(centroids.get(k))); double[] centroid = centroids.get(k); rmsdKmeans[k] = computeRootMeanSquare(centroid); } System.out.println("1 rmsd original -- " + Arrays.toString(rmsd)); System.out.println("2 rmsd k- Means -- " + Arrays.toString(rmsdKmeans)); System.out.println(); } } } client.close(); }
From source file:Main.java
public static void main(String[] args) { Map<Integer, String> grades = new HashMap<Integer, String>(); grades.put(1, "A"); grades.put(2, "B"); grades.put(3, "C"); grades.put(4, "D"); grades.put(5, "E"); String value = grades.get(1); List<String> dayNames = new ArrayList<String>(); dayNames.add("Sunday"); dayNames.add("Monday"); dayNames.add("Tuesday"); dayNames.add("Wednesday"); String firstDay = dayNames.get(0); }
From source file:com.github.stagirs.lingvo.build.SyntaxStatisticsBuilder.java
public static void main(String[] args) throws Exception { TObjectIntHashMap<String> map = new TObjectIntHashMap<String>(); for (String line : FileUtils.readLines(new File("annot.opcorpora.no_ambig.plain"), "utf-8")) { List<String> types = types(Annotation.parse(line)); if (types.isEmpty()) { continue; }/*from w w w .ja va 2 s .c o m*/ map.adjustOrPutValue(types.get(0), 1, 1); map.adjustOrPutValue(" " + types.get(0), 1, 1); for (int i = 1; i < types.size(); i++) { map.adjustOrPutValue(types.get(i), 1, 1); map.adjustOrPutValue(types.get(i - 1) + " " + types.get(i), 1, 1); } map.adjustOrPutValue(types.get(types.size() - 1) + " ", 1, 1); } final List<String> result = new ArrayList<String>(); map.forEachEntry(new TObjectIntProcedure<String>() { @Override public boolean execute(String key, int count) { result.add(key + "\t" + count); return true; } }); FileUtils.writeLines(new File("src/main/resources/SyntaxStatistics"), "utf-8", result); }
From source file:com.gargoylesoftware.htmlunit.source.TestCaseCreator.java
/** * The entry point.//ww w .jav a 2 s . co m * * @param args the arguments * @throws IOException if an error occurs */ public static void main(final String[] args) throws IOException { if (args.length == 0) { System.out.println("HTML file location is not provided"); return; } final File file = new File(args[0]); if (!file.exists()) { System.out.println("File does not exist " + file.getAbsolutePath()); } System.out.println(" /**"); System.out.println(" * @throws Exception if an error occurs"); System.out.println(" */"); System.out.println(" @Test"); System.out.println(" @Alerts()"); System.out.println(" public void test() throws Exception {"); final List<String> lines = FileUtils.readLines(file, TextUtil.DEFAULT_CHARSET); for (int i = 0; i < lines.size(); i++) { final String line = lines.get(i); if (i == 0) { System.out.println(" final String html = \"" + line.replace("\"", "\\\"") + "\\n\""); } else { System.out.print(" + \"" + line.replace("\"", "\\\"") + "\\n\""); if (i == lines.size() - 1) { System.out.print(";"); } System.out.println(); } } System.out.println(" loadPageWithAlerts2(html);"); System.out.println(" }"); }
From source file:Main.java
public static void main(String[] args) { List<String> aList = new ArrayList<String>(); Map<Integer, String> aMap = new HashMap<Integer, String>(); aList.add("A"); aList.add("B"); for (int i = 0; i < aList.size(); i++) { aMap.put(i + 1, aList.get(i)); }//from w w w. jav a2s .c o m System.out.println(aMap.toString()); }
From source file:net.meltdowntech.steamstats.SteamUser.java
public static void main(String[] args) { Util.startTimer();/*w ww. jav a 2 s .c o m*/ List<Long> ids = new ArrayList<>(); ids.add(76561198038145439L); List<SteamUser> users = fetchUsers(ids); users.get(0).fetchPlaytime(); users.get(0).fetchLevel(); Util.printInfo("Playtime " + users.get(0).getPlaytime()); Util.printInfo("Level " + users.get(0).getLevel()); }