Java Collections.fill Examples

Java Collections.fill - 12 examples found. These are the top rated real world Java examples of java.util.Collections.fill extracted from open source projects. You can rate examples to help us improve the quality of examples.
 public static void main(String[] args) {
   try {
     eq(
         0,
         (new BallsSeparating_2())
             .minOperations(new int[] {1, 1, 1}, new int[] {1, 1, 1}, new int[] {1, 1, 1}),
         6);
     eq(
         1,
         (new BallsSeparating_2()).minOperations(new int[] {5}, new int[] {6}, new int[] {8}),
         -1);
     eq(
         2,
         (new BallsSeparating_2())
             .minOperations(
                 new int[] {4, 6, 5, 7}, new int[] {7, 4, 6, 3}, new int[] {6, 5, 3, 8}),
         37);
     eq(
         3,
         (new BallsSeparating_2())
             .minOperations(
                 new int[] {7, 12, 9, 9, 7},
                 new int[] {7, 10, 8, 8, 9},
                 new int[] {8, 9, 5, 6, 13}),
         77);
     eq(
         4,
         (new BallsSeparating_2())
             .minOperations(
                 new int[] {
                   842398, 491273, 958925, 849859, 771363, 67803, 184892, 391907, 256150, 75799
                 },
                 new int[] {
                   268944, 342402, 894352, 228640, 903885, 908656, 414271, 292588, 852057, 889141
                 },
                 new int[] {
                   662939, 340220, 600081, 390298, 376707, 372199, 435097, 40266, 145590, 505103
                 }),
         7230607);
     int[] a = new int[50];
     int[] b = new int[50];
     int[] c = new int[50];
     fill(a, 1);
     fill(b, 1);
     fill(c, 1);
     eq(5, (new BallsSeparating_2()).minOperations(a, b, c), 7230607);
   } catch (Exception exx) {
     System.err.println(exx);
     exx.printStackTrace(System.err);
   }
 }
 private void reset() {
   isLooseMatch = false;
   Collections.fill(localVarMatches, null);
   for (int i = 0; i < paramNodeMatches.size(); i++) {
     this.paramNodeMatches.set(i, null);
   }
 }
Example #3
0
  public static void main(String[] args) {
    List<String> list = new ArrayList<String>();

    Collections.addAll(list, "A", "B", "C", "D", "E", "F", "G", "H", "I", "J");
    System.out.println(list);
    System.out.println("list.subList(3,8): " + list.subList(3, 8));
    System.out.println("list.subList(3,8).get(2): " + list.subList(3, 8).get(2));

    System.out.println("list.subList(3,8).set(2,\"B\"):");
    list.subList(3, 8).set(2, "B");
    System.out.println(list);
    System.out.println("list.indexOf(\"B\"): " + list.indexOf("B"));
    System.out.println("list.subList(3,8).indexOf(\"B\"): " + list.subList(3, 8).indexOf("B"));
    System.out.println(list);
    System.out.println("Collections.reverse(list.subList(3,8)):");
    Collections.reverse(list.subList(3, 8));
    System.out.println(list);
    System.out.println("Collections.rotate(list.subList(3,8), 2):");
    Collections.rotate(list.subList(3, 8), 2);
    System.out.println(list);
    System.out.println("Collections.fill(list.subList(3,8), \"X\"):");
    Collections.fill(list.subList(3, 8), "X");
    System.out.println(list);
    list.subList(3, 8).clear();
    System.out.println(list);
  }
Example #4
0
  int Query() {

    // You have to report the shortest path from Steven and Grace's home (vertex 0)
    // to reach their chosen hospital (vertex 1)
    //
    // write your answer here

    q = new PriorityQueue<IntegerPair>();
    weights = new Vector<Integer>();
    weights.setSize(V);
    Collections.fill(weights, Integer.MAX_VALUE); // initially all infinite

    q.offer(new IntegerPair(0, 0));
    weights.set(0, 0);

    return dijkstra();
  }
 public static void main(String[] args) {
   print(list);
   print(
       "'list' disjoint (Four)?: "
           + Collections.disjoint(list, Collections.singletonList("Four")));
   print("max: " + Collections.max(list));
   print("min: " + Collections.min(list));
   print("max w/ comparator: " + Collections.max(list, String.CASE_INSENSITIVE_ORDER));
   print("min w/ comparator: " + Collections.min(list, String.CASE_INSENSITIVE_ORDER));
   List<String> sublist = Arrays.asList("Four five six".split(" "));
   print("indexOfSubList: " + Collections.indexOfSubList(list, sublist));
   print("lastIndexOfSubList: " + Collections.lastIndexOfSubList(list, sublist));
   Collections.replaceAll(list, "one", "Yo");
   print("replaceAll: " + list);
   Collections.reverse(list);
   print("reverse: " + list);
   Collections.rotate(list, 3);
   print("rotate: " + list);
   List<String> source = Arrays.asList("in the matrix".split(" "));
   Collections.copy(list, source);
   print("copy: " + list);
   Collections.swap(list, 0, list.size() - 1);
   print("swap: " + list);
   Collections.shuffle(list, new Random(47));
   print("shuffled: " + list);
   Collections.fill(list, "pop");
   print("fill: " + list);
   print("frequency of 'pop': " + Collections.frequency(list, "pop"));
   List<String> dups = Collections.nCopies(3, "snap");
   print("dups: " + dups);
   print("'list' disjoint 'dups'?: " + Collections.disjoint(list, dups));
   // Getting an old-style Enumeration:
   Enumeration<String> e = Collections.enumeration(dups);
   Vector<String> v = new Vector<String>();
   while (e.hasMoreElements()) v.addElement(e.nextElement());
   // Converting an old-style Vector
   // to a List via an Enumeration:
   ArrayList<String> arrayList = Collections.list(v.elements());
   print("arrayList: " + arrayList);
 }
Example #6
0
 /**
  * Returns a Tree containing {@code n} values supplied by a given Supplier {@code s}.
  *
  * @param <T> Component type of the Tree
  * @param n The number of elements in the Tree
  * @param s The Supplier computing element values
  * @return A Tree of size {@code n}, where each element contains the result supplied by {@code s}.
  * @throws NullPointerException if {@code s} is null
  */
 static <T> Tree<T> fill(int n, Supplier<? extends T> s) {
   Objects.requireNonNull(s, "s is null");
   return Collections.fill(n, s, Tree.empty(), Tree::of);
 }