List of usage examples for java.util List addAll
boolean addAll(int index, Collection<? extends E> c);
From source file:Main.java
public static void main(String[] args) { List<String> arrayList = new ArrayList<String>(); arrayList.add("1"); arrayList.add("2"); arrayList.add("3"); Vector<String> v = new Vector<String>(); v.add("4");//from ww w .j a v a2s. c o m v.add("5"); // insert all elements of Vector to ArrayList at index 1 arrayList.addAll(1, v); for (String str : arrayList) System.out.println(str); }
From source file:com.doculibre.constellio.utils.license.ApplyLicenseUtils.java
/** * @param args//from w w w . jav a 2 s. c o m */ @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { URL licenceHeaderURL = ApplyLicenseUtils.class.getResource("LICENSE_HEADER"); File binDir = ClasspathUtils.getClassesDir(); File projectDir = binDir.getParentFile(); // File dryrunDir = new File(projectDir, "dryrun"); File licenceFile = new File(licenceHeaderURL.toURI()); List<String> licenceLines = readLines(licenceFile); // for (int i = 0; i < licenceLines.size(); i++) { // String licenceLine = licenceLines.get(i); // licenceLines.set(i, " * " + licenceLine); // } // licenceLines.add(0, "/**"); // licenceLines.add(" */"); List<File> javaFiles = (List<File>) org.apache.commons.io.FileUtils.listFiles(projectDir, new String[] { "java" }, true); for (File javaFile : javaFiles) { if (isValidPackage(javaFile)) { List<String> javaFileLines = readLines(javaFile); if (!javaFileLines.isEmpty()) { boolean modified = false; String firstLineTrim = javaFileLines.get(0).trim(); if (firstLineTrim.startsWith("package")) { modified = true; javaFileLines.addAll(0, licenceLines); } else if (firstLineTrim.startsWith("/**")) { int indexOfEndCommentLine = -1; loop2: for (int i = 0; i < javaFileLines.size(); i++) { String javaFileLine = javaFileLines.get(i); if (javaFileLine.indexOf("*/") != -1) { indexOfEndCommentLine = i; break loop2; } } if (indexOfEndCommentLine != -1) { modified = true; int i = 0; loop3: for (Iterator<String> it = javaFileLines.iterator(); it.hasNext();) { it.next(); if (i <= indexOfEndCommentLine) { it.remove(); } else { break loop3; } i++; } javaFileLines.addAll(0, licenceLines); } else { throw new RuntimeException( "Missing end comment for file " + javaFile.getAbsolutePath()); } } if (modified) { // String outputFilePath = javaFile.getPath().substring(projectDir.getPath().length()); // File outputFile = new File(dryrunDir, outputFilePath); // outputFile.getParentFile().mkdirs(); // System.out.println(outputFile.getPath()); // FileOutputStream fos = new FileOutputStream(outputFile); System.out.println(javaFile.getPath()); FileOutputStream fos = new FileOutputStream(javaFile); IOUtils.writeLines(javaFileLines, "\n", fos); IOUtils.closeQuietly(fos); } } } } }
From source file:com.google.android.apps.santatracker.games.cityquiz.CityQuizUtil.java
/** * Retrieve a random list of cities.// w w w . jav a 2s. com * * @param amt Max number of cities to retrieve. * * @return Random list of cities. If amt is more than the amount of cities available, all cities are returned. */ public static List<City> getCities(Context context, int amt) { List<City> allCities = getCities(context); Collections.shuffle(allCities, new Random()); if (amt > allCities.size()) { amt = allCities.size(); } // Only return the cities that will be used in the game. List<City> cities = new ArrayList<>(); cities.addAll(0, allCities.subList(0, amt)); return cities; }
From source file:Main.java
public static <T> void addFirstAndRemoveOldIfNeed(List<T> dest, List<T> src) { if (dest == null) { return;/*from w w w . j ava 2 s. c om*/ } if (src == null || src.isEmpty()) { return; } removeDuplicate(dest, src); dest.addAll(0, src); }
From source file:Main.java
/** * Introduces overlap into a series of lists. * @param before # of elements from the end of the previous list to prepend * @param after # of elements from the beginning of the next list to append *//*from w ww. ja va2 s .c om*/ public static <T> List<List<T>> overlap(List<List<T>> lists, int before, int after) { if (before < 0) { throw new IllegalArgumentException("Value of before cannot be negative"); } if (after < 0) { throw new IllegalArgumentException("Value of after cannot be negative"); } ListIterator<List<T>> iter = lists.listIterator(); List<List<T>> result = new ArrayList<List<T>>(); for (; iter.hasNext();) { List<T> current = new ArrayList<T>(iter.next()); List<T> prev = before > 0 ? findPrevious(iter) : null; List<T> next = after > 0 ? findNext(iter) : null; if (prev != null) { List<T> overlap = prev.subList(prev.size() - before, prev.size()); current.addAll(0, overlap); } if (next != null) { List<T> overlap = next.subList(0, after); current.addAll(overlap); } result.add(current); } return result; }