List of usage examples for java.util Collections reverse
@SuppressWarnings({ "rawtypes", "unchecked" }) public static void reverse(List<?> list)
This method runs in linear time.
From source file:Util.java
public static <T> List<T> reverse(T[] array) { List<T> list = Arrays.asList(array); Collections.reverse(list); return list; }
From source file:Main.java
public static void reverseMethod() { ArrayList<String> list = new ArrayList<String>(); list.add("Z"); list.add("A"); list.add("K"); list.add("N"); System.out.println(list);/* w ww. ja va2s.com*/ Collections.reverse(list); System.out.println(list); }
From source file:Main.java
/** * Create a new instance of list which has elements in reverse order * @param list list of String/*from w w w .j a v a 2 s .c o m*/ * @return reversed list */ public static List<String> reverse(List<String> list) { List<String> reversedList = new ArrayList<String>(list); Collections.reverse(reversedList); return reversedList; }
From source file:Main.java
public static byte[] reverse(final byte[] bytes) { Objects.requireNonNull(bytes); if (bytes.length == 0) { return new byte[0]; }/*from w w w .j a va 2 s. c om*/ final List<Byte> list = asList(bytes); Collections.reverse(list); return toArray(list); }
From source file:Main.java
private static ArrayList<Double> getExactRatios(int motorTeeth, int[] wheelTeeth) { exactRatios.clear();//from www .java 2 s.c om for (int tooth : wheelTeeth) { exactRatios.add((double) tooth / (double) motorTeeth); } Collections.sort(exactRatios); // sort ascending Collections.reverse(exactRatios); // reverse to sort descending // now the zeroth element contains the highest gear ratio i.e. the lowest gear index return exactRatios; }
From source file:Main.java
public static List<Integer> reverse(List<Integer> aList) { List<Integer> tmp = new LinkedList<>(aList); Collections.reverse(tmp); return tmp;/*from w w w.ja v a2 s . c om*/ }
From source file:Main.java
public static Collection<Integer> seq(int start, int stop) { List<Integer> l = new ArrayList<Integer>(Math.abs(stop - start)); for (int i = Math.min(start, stop); i <= Math.max(start, stop); i++) { l.add(i);// w w w . j a va2 s .c o m } if (stop < start) Collections.reverse(l); return l; }
From source file:Main.java
/** * @param integer The integer to be converted * @param n the number of bits of the output binary * @return Array of binary number where arr(0) is the most significant *///from www . j a va 2 s .co m public static ArrayList<Boolean> decimalToBinary(Integer integer, int n) { ArrayList<Boolean> result = new ArrayList(); if (integer == 0) { result.add(false); for (int i = 0; i < n - 1; i++) result.add(false); Collections.reverse(result); return result; } while (integer != 0) { if (integer % 2 != 0) result.add(true); else result.add(false); integer = integer / 2; } // Fill the rest of the bits for (int i = 0; i < (n - result.size()); i++) result.add(false); Collections.reverse(result); return result; }
From source file:Main.java
/** * Creates a list by pulling off the head of a queue one item at a time and * adding it to an output list. The input queue is emptied by this method. * // w w w .j a v a 2 s. c om * @param <T> * @param queue * @param outputList * @param reverse * whether or not to reverse the resulting list * @return */ public static <T> List<T> createList(Queue<T> queue, List<T> outputList, boolean reverse) { if (outputList == null) { outputList = new ArrayList<T>(queue.size()); } while (!queue.isEmpty()) { outputList.add(queue.poll()); } if (reverse) { Collections.reverse(outputList); } return outputList; }
From source file:Main.java
public static <A> boolean isSuffixOf(final List<A> ls1, final List<A> ls2) { if (ls1 == null) { return true; }/* w ww . j a v a 2s.c om*/ if (ls2 == null) { return false; } if (ls1.size() > ls2.size()) { return false; } final List<A> ls1Rev = new LinkedList<A>(ls1); final List<A> ls2Rev = new LinkedList<A>(ls2); Collections.reverse(ls1Rev); Collections.reverse(ls2Rev); return isPrefixOf(ls1Rev, ls2Rev); }