List<String> stockList = new ArrayList<String>(); stockList.add("stock1"); stockList.add("stock2"); String[] stockArr = new String[stockList.size()]; stockArr = stockList.toArray(stockArr); for(String s : stockArr) System.out.println(s);
List<String> strings = new ArrayList<String>() strings.add("lol"); strings.add("cat"); Collections.sort(strings); for (String s : strings) { System.out.println(s); } // Prints out "cat" and "lol"
private String getAssetPath (GeneratorContext context) { ConfigurationProperty assetPathProperty = null; try { assetPathProperty = context.getPropertyOracle().getConfigurationProperty("gdx.assetpath"); } catch (BadPropertyValueException e) { throw new RuntimeException( "No gdx.assetpath defined. Add <set-configuration-property name=\"gdx.assetpath\" value=\"relative/path/to/assets/\"/> to your GWT projects gwt.xml file"); } if (assetPathProperty.getValues().size() == 0) { throw new RuntimeException( "No gdx.assetpath defined. Add <set-configuration-property name=\"gdx.assetpath\" value=\"relative/path/to/assets/\"/> to your GWT projects gwt.xml file"); } String paths = assetPathProperty.getValues().get(0); if(paths == null) { throw new RuntimeException( "No gdx.assetpath defined. Add <set-configuration-property name=\"gdx.assetpath\" value=\"relative/path/to/assets/\"/> to your GWT projects gwt.xml file"); } else { ArrayList<String> existingPaths = new ArrayList<String>(); String[] tokens = paths.split(","); for(String token: tokens) { System.out.println(token); if(new FileWrapper(token).exists() || new FileWrapper("../" + token).exists()) { return token; } } throw new RuntimeException( "No valid gdx.assetpath defined. Fix <set-configuration-property name=\"gdx.assetpath\" value=\"relative/path/to/assets/\"/> in your GWT projects gwt.xml file"); } }
public static void main( String [] args ) throws IOException { fileQuickSort( new File("input"), new File("output")); System.out.println(); Scanner scanner = new Scanner( new BufferedInputStream( new FileInputStream( inputFile ), MAX_SIZE)); scanner.useDelimiter(","); System.out.print("-"); PrintStream greater = createPrintStream(greaterFile); PrintStream target = null; int pivot = scanner.nextInt(); int current = scanner.nextInt(); scanner.close(); lower.close(); greater.close(); System.out.print("."); List<Integer> smallFileIntegers = new ArrayList<Integer>(); smallFileIntegers.add( scanner.nextInt() ); scanner.close();
String[] arr = new String[1]; arr[0] = "rohit"; List<String> newList = Arrays.asList(arr); // Will throw `UnsupportedOperationException // newList.add("jain"); // Can't do this. ArrayList<String> updatableList = new ArrayList<String>(); updatableList.addAll(newList); updatableList.add("jain"); // OK this is fine. System.out.println(newList); // Prints [rohit] System.out.println(updatableList); //Prints [rohit, jain]
// Substitute appropriate type. ArrayList<...> a = new ArrayList<...>(); // Add elements to list. // Generate an iterator. Start just after the last element. ListIterator li = a.listIterator(a.size()); // Iterate in reverse. while(li.hasPrevious()) { System.out.println(li.previous()); }
List<Integer> nodeIds = Lists.newArrayList(); System.out.print("\nNew metadata: \n" + value.toString() + "\n"); System.out.print("\nAffected nodes:\n"); System.out.format("+-------+------+---------------------------------+----------+---------+------------------+%n"); System.out.printf("|Id |Zone |Host |SocketPort|AdminPort|NumberOfPartitions|%n"); nodeIds.add(node.getId()); System.out.format("| %-5d | %-4d | %-31s | %-5d | %-5d | %-5d |%n", node.getId(), System.out.print("Do you want to proceed? [Y/N]: "); Scanner in = new Scanner(System.in); String choice = in.nextLine(); return false; } else { System.out.println("Incorrect response detected. Exiting."); return false;
/** * Reads the Label file, the file which contains the Mary context features, creates an scanner object and calls getTargets * * @param LabFile * LabFile * @param htsData * htsData * @throws Exception * Exception * @return targets */ public static List<Target> getTargetsFromFile(String LabFile, HMMData htsData) throws Exception { List<Target> targets = null; Scanner s = null; try { /* parse text in label file */ s = new Scanner(new BufferedReader(new FileReader(LabFile))); targets = getTargets(s, htsData); } catch (FileNotFoundException e) { System.err.println("FileNotFoundException: " + e.getMessage()); } finally { if (s != null) s.close(); } return targets; }
Scanner sc = new Scanner(System.in); while (!sc.hasNext("exit")) { System.out.println( sc.hasNextInt() ? "(int) " + sc.nextInt() : sc.hasNextLong() ? "(long) " + sc.nextLong() : sc.hasNextDouble() ? "(double) " + sc.nextDouble() : sc.hasNextBoolean() ? "(boolean) " + sc.nextBoolean() : "(String) " + sc.next() ); }
/** * 测试多表联合查询 in */ @RequestMapping(value = "/testTandUIn", produces = "text/html") @ResponseBody public void testTandUIn(){ List<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(2); List<TeacherVo> teacherAndUser = userMapper.getTeacherAndUserList(list); System.out.println(teacherAndUser.size()); }
List<Integer> numbers = new ArrayList<Integer>( Arrays.asList(5,3,1,2,9,5,0,7) ); List<Integer> head = numbers.subList(0, 4); List<Integer> tail = numbers.subList(4, 8); System.out.println(head); // prints "[5, 3, 1, 2]" System.out.println(tail); // prints "[9, 5, 0, 7]" Collections.sort(head); System.out.println(numbers); // prints "[1, 2, 3, 5, 9, 5, 0, 7]" tail.add(-1); System.out.println(numbers); // prints "[1, 2, 3, 5, 9, 5, 0, 7, -1]"