List of usage examples for java.util Collections sort
@SuppressWarnings("unchecked") public static <T extends Comparable<? super T>> void sort(List<T> list)
From source file:Main.java
/** Returns two ArrayLists, containing the elements only present in the first and second argument, respectively. */ @SuppressWarnings("unchecked") public static ArrayList<String>[] getUniqueElements(Collection<? extends String> list1, Collection<? extends String> list2) { final ArrayList<String> onlyInOne = new ArrayList<String>(list1); onlyInOne.removeAll(list2);/*from w ww. j av a2 s . c om*/ Collections.sort(onlyInOne); final ArrayList<String> onlyInTwo = new ArrayList<String>(list2); onlyInTwo.removeAll(list1); Collections.sort(onlyInTwo); return new ArrayList[] { onlyInOne, onlyInTwo }; }
From source file:Main.java
public static final List<String> getListFromBundle(ResourceBundle rb, String prefix) { String name = null;//w w w. j a v a 2 s . c o m List<String> ret = new LinkedList<String>(); Enumeration<String> names = rb.getKeys(); while (names.hasMoreElements()) { name = names.nextElement(); if (name != null && name.startsWith(prefix) && isInteger(name.substring(name.length() - 1))) { ret.add(rb.getString(name)); } } Collections.sort(ret); return ret; }
From source file:Main.java
/** * /* w ww . j a v a 2 s . c o m*/ * @param <T> * @param a * variable number of arguments of type <T> * @return */ public static <T extends Comparable<T>> T lowestValue(T... a) { if (null == a || a.length <= 0) return null; List<T> list = new ArrayList<T>(); for (T t : a) { if (null != t) { list.add(t); } } Collections.sort(list); return list.get(0); }
From source file:Main.java
public static List<BigDecimal> intervals(final List<BigDecimal> list) { // list must be sorted for interval calculation Collections.sort(list); final List<BigDecimal> retVal = new ArrayList<BigDecimal>(); BigDecimal before = list.get(0); for (int i = 1; i < list.size(); i++) { final BigDecimal current = list.get(i); retVal.add(current.subtract(before)); before = current;/*from w w w . j av a 2 s . com*/ } return retVal; }
From source file:Main.java
/** * Return the items of an Iterable as a sorted list. * * @param <T>//w w w . j a va 2 s. c om * The type of items in the Iterable. * @param items * The collection to be sorted. * @return A list containing the same items as the Iterable, but sorted. */ public static <T extends Comparable<T>> List<T> sorted(Iterable<T> items) { List<T> result = toList(items); Collections.sort(result); return result; }
From source file:Main.java
/** * Get the sorted selected positions in a byte with the right most * position as zero./* ww w . j a v a 2 s.c o m*/ * @param input Byte to be evaluated * @return Array of integer positions. */ public static SortedSet<Integer> getSelectedPCR(byte input) { ArrayList<Integer> arrayList = new ArrayList<Integer>(); byte mask = 0x01; for (int i = 0; i <= 7; i++) { int value = (input >>> i) & mask; if (value == 1) { arrayList.add(i); } } Collections.sort(arrayList); return Collections.unmodifiableSortedSet(new TreeSet<Integer>(arrayList)); }
From source file:Main.java
public static String getBinaryHash(Activity activity) throws IOException, NoSuchAlgorithmException { ArrayList<String> manifestEntries = new ArrayList<String>(); addFolderEntriesToManifest(manifestEntries, "www", activity.getAssets()); Collections.sort(manifestEntries); JSONArray manifestJSONArray = new JSONArray(); for (String manifestEntry : manifestEntries) { manifestJSONArray.put(manifestEntry); }// ww w . j a v a 2 s . com // The JSON serialization turns path separators into "\/", e.g. "www\/images\/image.png" String manifestString = manifestJSONArray.toString().replace("\\/", "/"); return computeHash(new ByteArrayInputStream(manifestString.getBytes())); }
From source file:com.coderadar.controller.MainController.java
public static void main(String[] args) { List<String> sortList = new ArrayList<String>(); sortList.add("tc-5.5.x"); sortList.add("tc-6.0.x"); sortList.add("tc-7.0.x"); sortList.add("tc-8.0.x"); sortList.add("trunk"); Collections.sort(sortList); Collections.sort(sortList, Collections.reverseOrder()); System.out.println(""); }
From source file:Main.java
public static ArrayList<String> getCountriesArray() { String[] locales = Locale.getISOCountries(); ArrayList<String> countries = new ArrayList<String>(); for (String countryCode : locales) { Locale locale = new Locale("", countryCode); try {//from ww w.j a v a 2 s . c o m Currency currency = Currency.getInstance(locale); countries.add(locale.getDisplayCountry() + " (" + currency.getCurrencyCode() + ")"); } catch (Exception e) { } } Collections.sort(countries); return countries; }
From source file:Main.java
/** Sorts given list and returns it. */ public static <E extends Comparable<? super E>, L extends List<E>> L sort(L list) { Collections.sort(list); return list;//from www . j av a 2s . c om }