public static void main(String[] args) { String[] sa = new Rand.String().array(20); show("Before sort", sa); Arrays.sort(sa); show("After sort", sa); Arrays.sort(sa, Collections.reverseOrder()); show("Reverse sort", sa); Arrays.sort(sa, String.CASE_INSENSITIVE_ORDER); show("Case-insensitive sort", sa); } }
String[] a9 = new String[size]; Arrays.fill(a1, true); show("a1", a1); Arrays.fill(a2, (byte)11); show("a2", a2); Arrays.fill(a3, 'x'); show("a3", a3); Arrays.fill(a4, (short)17); show("a4", a4); Arrays.fill(a5, 19); show("a5", a5); Arrays.fill(a6, 23); show("a6", a6); Arrays.fill(a7, 29); show("a7", a7); Arrays.fill(a8, 47); show("a8", a8); Arrays.fill(a9, "Hello"); show("a9", a9); show("a9", a9);
public static void main(String[] args) { long[] l1 = fillCounted(20); // No problem show(l1); // On my machine, this runs out of heap space: //- long[] l2 = fillCounted(10_000_000); } }
public static void main(String[] args) { for(int i = 0; i < 7; i++) show(flavorSet(3)); } }
public static void main(String[] args) { BerylliumSphere[] spheres = new BerylliumSphere[10]; for(int i = 0; i < 5; i++) spheres[i] = new BerylliumSphere(); show(spheres); System.out.println(spheres[4]); List<BerylliumSphere> sphereList = Suppliers.create( ArrayList::new, BerylliumSphere::new, 5); System.out.println(sphereList); System.out.println(sphereList.get(4)); int[] integers = { 0, 1, 2, 3, 4, 5 }; show(integers); System.out.println(integers[4]); List<Integer> intList = new ArrayList<>( Arrays.asList(0, 1, 2, 3, 4, 5)); intList.add(97); System.out.println(intList); System.out.println(intList.get(4)); } }
public static void main(String[] args) { String[] sa = new Rand.String().array(30); Arrays.sort(sa, String.CASE_INSENSITIVE_ORDER); show(sa); int index = Arrays.binarySearch(sa, sa[10], String.CASE_INSENSITIVE_ORDER); System.out.println( "Index: "+ index + "\n"+ sa[index]); } }
public static void main(String[] args) { int[] ia = new int[SZ]; long[] la = new long[SZ]; double[] da = new double[SZ]; Arrays.setAll(ia, n -> n); // [1] Arrays.setAll(la, n -> n); Arrays.setAll(da, n -> n); show(ia); show(la); show(da); Arrays.setAll(ia, n -> val++); // [2] Arrays.setAll(la, n -> val++); Arrays.setAll(da, n -> val++); show(ia); show(la); show(da); Bob[] ba = new Bob[SZ]; Arrays.setAll(ba, Bob::new); // [3] show(ba); Character[] ca = new Character[SZ]; Arrays.setAll(ca, SimpleSetAll::getChar); // [4] show(ca); } }
public static void main(String[] args) { int[] a1 = new int[SZ]; Arrays.setAll(a1, new Count.Integer()::get); show("a1", a1); int[] a2 = Arrays.copyOf(a1, a1.length); // [1] show("a1", a1); show("a2", a2); show("a2", a2); show("a2", a2); Arrays.setAll(a3, new Count.Integer()::get); Integer[] a4 = Arrays.copyOfRange(a3, 4, 12); show("a4", a4); show(b); show(d2);
public static void main(String[] args) { int[] nums = new Count.Pint().array(10); show(nums); System.out.println(Arrays.stream(nums) .reduce(Integer::sum).getAsInt()); Arrays.parallelPrefix(nums, Integer::sum); show(nums); System.out.println(Arrays.stream( new Count.Pint().array(6)) .reduce(Integer::sum).getAsInt()); } }
public static void main(String[] args) { Rand.Pint rand = new Rand.Pint(); int[] a = new Rand.Pint().array(25); Arrays.sort(a); show("Sorted array", a); while(true) { int r = rand.getAsInt(); int location = Arrays.binarySearch(a, r); if(location >= 0) { System.out.println( "Location of " + r + " is " + location + ", a[" + location + "] is " + a[location]); break; // Out of while loop } } } }
Arrays.setAll(a1, new Rand.Boolean()::get); boolean[] a1p = primitive(a1); show("a1p", a1p); Boolean[] a1b = boxed(a1p); show("a1b", a1b); show("a2p", a2p); Byte[] a2b = boxed(a2p); show("a2b", a2b); show("a3p", a3p); Character[] a3b = boxed(a3p); show("a3b", a3b); show("a4p", a4p); Short[] a4b = boxed(a4p); show("a4b", a4b); show("a5p", a5p); Integer[] a5b = boxed(a5p); show("a5b", a5b); show("a6p", a6p); Long[] a6b = boxed(a6p); show("a6b", a6b); show("a7p", a7p); Float[] a7b = boxed(a7p); show("a7b", a7b);
Boolean[] a1 = new Boolean[SZ]; Arrays.setAll(a1, new Count.Boolean()::get); show(a1); a1 = Stream.generate(new Count.Boolean()) .limit(SZ + 1).toArray(Boolean[]::new); show(a1); a1 = new Count.Boolean().array(SZ + 2); show(a1); boolean[] a1b = new Count.Pboolean().array(SZ + 3); show(a1b); show(a2); a2 = Stream.generate(new Count.Byte()) .limit(SZ + 1).toArray(Byte[]::new); show(a2); a2 = new Count.Byte().array(SZ + 2); show(a2); byte[] a2b = new Count.Pbyte().array(SZ + 3); show(a2b); show(a3); a3 = Stream.generate(new Count.Character()) .limit(SZ + 1).toArray(Character[]::new); show(a3); a3 = new Count.Character().array(SZ + 2); show(a3); char[] a3b = new Count.Pchar().array(SZ + 3); show(a3b);
Boolean[] a1 = new Boolean[SZ]; Arrays.setAll(a1, new Rand.Boolean()::get); show(a1); a1 = Stream.generate(new Rand.Boolean()) .limit(SZ + 1).toArray(Boolean[]::new); show(a1); a1 = new Rand.Boolean().array(SZ + 2); show(a1); boolean[] a1b = new Rand.Pboolean().array(SZ + 3); show(a1b); show(a2); a2 = Stream.generate(new Rand.Byte()) .limit(SZ + 1).toArray(Byte[]::new); show(a2); a2 = new Rand.Byte().array(SZ + 2); show(a2); byte[] a2b = new Rand.Pbyte().array(SZ + 3); show(a2b); show(a3); a3 = Stream.generate(new Rand.Character()) .limit(SZ + 1).toArray(Character[]::new); show(a3); a3 = new Rand.Character().array(SZ + 2); show(a3); char[] a3b = new Rand.Pchar().array(SZ + 3); show(a3b);