Java : Arrays (配列操作) - API使用例
Arrays (Java SE 18 & JDK 18) の使用例まとめです。
だいたいのメソッドを網羅済みです。
API仕様のおともにどうぞ。
概要
Arraysクラスには、
- ソート
- 検索
- 比較
などなど、配列を操作するためのメソッドがいろいろとそろっています。
final String[] array = {"aaa", "bbb", "ccc"};
final var str = Arrays.toString(array);
System.out.println(str); // [aaa, bbb, ccc]
final int[] array = {2, 1, 5, 4, 3};
Arrays.sort(array);
System.out.println(Arrays.toString(array)); // [1, 2, 3, 4, 5]
final int[] array1 = {1, 2, 3};
final int[] array2 = {1, 2, 3};
System.out.println(array1.equals(array2)); // false
System.out.println(Arrays.equals(array1, array2)); // true
System.out.println(array1.hashCode()); // 37981645
System.out.println(array2.hashCode()); // 605052357
System.out.println(Arrays.hashCode(array1)); // 30817
System.out.println(Arrays.hashCode(array2)); // 30817
コード例として共通で使うクラス
本記事のコード例では、以下のクラスを共通で使います。
主に Comparator を必要とするAPIのためです。
// 2つの整数をもつレコードクラスです。
record Pair(int first, int second) {
@Override
public String toString() {
return "(%d, %d)".formatted(first, second);
}
}
// Pairクラスを大小比較するためのクラスです。
class PairComparator implements Comparator<Pair> {
@Override
public int compare(Pair o1, Pair o2) {
if (o1.first() == o2.first()) {
return o1.second() - o2.second();
} else {
return o1.first() - o2.first();
}
}
}
メソッド
static <T> List<T> asList (T... a)
final List<String> list = Arrays.asList("aaa", "bbb", "ccc");
System.out.println(list); // [aaa, bbb, ccc]
// 配列を指定してもOKです。
final String[] array = {"aaa", "bbb", "ccc"};
final List<String> list = Arrays.asList(array);
System.out.println(list); // [aaa, bbb, ccc]
final List<Integer> list = Arrays.asList(1, 999, 12345);
System.out.println(list); // [1, 999, 12345]
static int binarySearch (byte[] a, byte key)
型が違うこと以外は、binarySearch(int[] a, int key)と使い方は同じです。
API使用例はそちらをご参照ください。
static int binarySearch (byte[] a, int fromIndex, int toIndex, byte key)
型が違うこと以外は、binarySearch(int[] a, int fromIndex, int toIndex, int key)と使い方は同じです。
API使用例はそちらをご参照ください。
static int binarySearch (char[] a, char key)
final char[] a = {'a', 'z', 'b', 'y', 'c', 'x'};
// 対象となる配列はソートされていることが必要です。
Arrays.sort(a);
System.out.println(Arrays.toString(a)); // [a, b, c, x, y, z]
System.out.println(Arrays.binarySearch(a, 'a')); // 0
System.out.println(Arrays.binarySearch(a, 'b')); // 1
System.out.println(Arrays.binarySearch(a, 'c')); // 2
System.out.println(Arrays.binarySearch(a, 'x')); // 3
System.out.println(Arrays.binarySearch(a, 'y')); // 4
System.out.println(Arrays.binarySearch(a, 'z')); // 5
System.out.println(Arrays.binarySearch(a, 'g')); // -4
static int binarySearch (char[] a, int fromIndex, int toIndex, char key)
final char[] a = {'a', 'z', 'b', 'y'};
// 対象となる配列はソートされていることが必要です。
Arrays.sort(a);
System.out.println(Arrays.toString(a)); // [a, b, y, z]
System.out.println(Arrays.binarySearch(a, 0, 4, 'a')); // 0
System.out.println(Arrays.binarySearch(a, 0, 4, 'b')); // 1
System.out.println(Arrays.binarySearch(a, 0, 4, 'y')); // 2
System.out.println(Arrays.binarySearch(a, 0, 4, 'z')); // 3
System.out.println(Arrays.binarySearch(a, 0, 4, 'g')); // -3
System.out.println(Arrays.binarySearch(a, 1, 4, 'a')); // -2
System.out.println(Arrays.binarySearch(a, 1, 4, 'b')); // 1
System.out.println(Arrays.binarySearch(a, 1, 4, 'y')); // 2
System.out.println(Arrays.binarySearch(a, 1, 4, 'z')); // 3
System.out.println(Arrays.binarySearch(a, 0, 3, 'a')); // 0
System.out.println(Arrays.binarySearch(a, 0, 3, 'b')); // 1
System.out.println(Arrays.binarySearch(a, 0, 3, 'y')); // 2
System.out.println(Arrays.binarySearch(a, 0, 3, 'z')); // -4
static int binarySearch (double[] a, double key)
型が違うこと以外は、binarySearch(int[] a, int key)と使い方は同じです。
API使用例はそちらをご参照ください。
static int binarySearch (double[] a, int fromIndex, int toIndex, double key)
型が違うこと以外は、binarySearch(int[] a, int fromIndex, int toIndex, int key)と使い方は同じです。
API使用例はそちらをご参照ください。
static int binarySearch (float[] a, float key)
型が違うこと以外は、binarySearch(int[] a, int key)と使い方は同じです。
API使用例はそちらをご参照ください。
static int binarySearch (float[] a, int fromIndex, int toIndex, float key)
型が違うこと以外は、binarySearch(int[] a, int fromIndex, int toIndex, int key)と使い方は同じです。
API使用例はそちらをご参照ください。
static int binarySearch (int[] a, int key)
final int[] a = {1, 10, 2, 20, 3, 30};
// 対象となる配列はソートされていることが必要です。
Arrays.sort(a);
System.out.println(Arrays.toString(a)); // [1, 2, 3, 10, 20, 30]
System.out.println(Arrays.binarySearch(a, 1)); // 0
System.out.println(Arrays.binarySearch(a, 2)); // 1
System.out.println(Arrays.binarySearch(a, 3)); // 2
System.out.println(Arrays.binarySearch(a, 10)); // 3
System.out.println(Arrays.binarySearch(a, 20)); // 4
System.out.println(Arrays.binarySearch(a, 30)); // 5
System.out.println(Arrays.binarySearch(a, 999)); // -7
static int binarySearch (int[] a, int fromIndex, int toIndex, int key)
final int[] a = {1, 10, 2, 20};
// 対象となる配列はソートされていることが必要です。
Arrays.sort(a);
System.out.println(Arrays.toString(a)); // [1, 2, 10, 20]
System.out.println(Arrays.binarySearch(a, 0, 4, 1)); // 0
System.out.println(Arrays.binarySearch(a, 0, 4, 2)); // 1
System.out.println(Arrays.binarySearch(a, 0, 4, 10)); // 2
System.out.println(Arrays.binarySearch(a, 0, 4, 20)); // 3
System.out.println(Arrays.binarySearch(a, 0, 4, 999)); // -5
System.out.println(Arrays.binarySearch(a, 1, 4, 1)); // -2
System.out.println(Arrays.binarySearch(a, 1, 4, 2)); // 1
System.out.println(Arrays.binarySearch(a, 1, 4, 10)); // 2
System.out.println(Arrays.binarySearch(a, 1, 4, 20)); // 3
System.out.println(Arrays.binarySearch(a, 0, 3, 1)); // 0
System.out.println(Arrays.binarySearch(a, 0, 3, 2)); // 1
System.out.println(Arrays.binarySearch(a, 0, 3, 10)); // 2
System.out.println(Arrays.binarySearch(a, 0, 3, 20)); // -4
static int binarySearch (long[] a, int fromIndex, int toIndex, long key)
型が違うこと以外は、binarySearch(int[] a, int fromIndex, int toIndex, int key)と使い方は同じです。
API使用例はそちらをご参照ください。
static int binarySearch (long[] a, long key)
型が違うこと以外は、binarySearch(int[] a, int key)と使い方は同じです。
API使用例はそちらをご参照ください。
static int binarySearch (short[] a, int fromIndex, int toIndex, short key)
型が違うこと以外は、binarySearch(int[] a, int fromIndex, int toIndex, int key)と使い方は同じです。
API使用例はそちらをご参照ください。
static int binarySearch (short[] a, short key)
型が違うこと以外は、binarySearch(int[] a, int key)と使い方は同じです。
API使用例はそちらをご参照ください。
static int binarySearch (Object[] a, int fromIndex, int toIndex, Object key)
final String[] a = {"a", "z", "b", "y"};
// 対象となる配列はソートされていることが必要です。
Arrays.sort(a);
System.out.println(Arrays.toString(a)); // [a, b, y, z]
System.out.println(Arrays.binarySearch(a, 0, 4, "a")); // 0
System.out.println(Arrays.binarySearch(a, 0, 4, "b")); // 1
System.out.println(Arrays.binarySearch(a, 0, 4, "y")); // 2
System.out.println(Arrays.binarySearch(a, 0, 4, "z")); // 3
System.out.println(Arrays.binarySearch(a, 0, 4, "g")); // -3
System.out.println(Arrays.binarySearch(a, 1, 4, "a")); // -2
System.out.println(Arrays.binarySearch(a, 1, 4, "b")); // 1
System.out.println(Arrays.binarySearch(a, 1, 4, "y")); // 2
System.out.println(Arrays.binarySearch(a, 1, 4, "z")); // 3
System.out.println(Arrays.binarySearch(a, 0, 3, "a")); // 0
System.out.println(Arrays.binarySearch(a, 0, 3, "b")); // 1
System.out.println(Arrays.binarySearch(a, 0, 3, "y")); // 2
System.out.println(Arrays.binarySearch(a, 0, 3, "z")); // -4
static int binarySearch (Object[] a, Object key)
final String[] a = {"a", "z", "b", "y", "c", "x"};
// 対象となる配列はソートされていることが必要です。
Arrays.sort(a);
System.out.println(Arrays.toString(a)); // [a, b, c, x, y, z]
System.out.println(Arrays.binarySearch(a, "a")); // 0
System.out.println(Arrays.binarySearch(a, "b")); // 1
System.out.println(Arrays.binarySearch(a, "c")); // 2
System.out.println(Arrays.binarySearch(a, "x")); // 3
System.out.println(Arrays.binarySearch(a, "y")); // 4
System.out.println(Arrays.binarySearch(a, "z")); // 5
System.out.println(Arrays.binarySearch(a, "g")); // -4
static <T> int binarySearch (T[] a, int fromIndex, int toIndex, T key, Comparator<? super T> c)
PairとPairComparatorについてはこちらをご参照ください。
final Pair[] a = {
new Pair(2, 1),
new Pair(2, 2),
new Pair(1, 1),
new Pair(1, 2)
};
final var c = new PairComparator();
// 対象となる配列はソートされていることが必要です。
Arrays.sort(a, c);
System.out.println(Arrays.toString(a)); // [(1, 1), (1, 2), (2, 1), (2, 2)]
System.out.println(Arrays.binarySearch(a, 0, 4, new Pair(1, 1), c)); // 0
System.out.println(Arrays.binarySearch(a, 0, 4, new Pair(1, 2), c)); // 1
System.out.println(Arrays.binarySearch(a, 0, 4, new Pair(2, 1), c)); // 2
System.out.println(Arrays.binarySearch(a, 0, 4, new Pair(2, 2), c)); // 3
System.out.println(Arrays.binarySearch(a, 0, 4, new Pair(3, 3), c)); // -5
System.out.println(Arrays.binarySearch(a, 1, 4, new Pair(1, 1), c)); // -2
System.out.println(Arrays.binarySearch(a, 1, 4, new Pair(1, 2), c)); // 1
System.out.println(Arrays.binarySearch(a, 1, 4, new Pair(2, 1), c)); // 2
System.out.println(Arrays.binarySearch(a, 1, 4, new Pair(2, 2), c)); // 3
System.out.println(Arrays.binarySearch(a, 0, 3, new Pair(1, 1), c)); // 0
System.out.println(Arrays.binarySearch(a, 0, 3, new Pair(1, 2), c)); // 1
System.out.println(Arrays.binarySearch(a, 0, 3, new Pair(2, 1), c)); // 2
System.out.println(Arrays.binarySearch(a, 0, 3, new Pair(2, 2), c)); // -4
static <T> int binarySearch (T[] a, T key, Comparator<? super T> c)
PairとPairComparatorについてはこちらをご参照ください。
final Pair[] a = {
new Pair(2, 1),
new Pair(2, 2),
new Pair(1, 1),
new Pair(1, 2)
};
final var c = new PairComparator();
// 対象となる配列はソートされていることが必要です。
Arrays.sort(a, c);
System.out.println(Arrays.toString(a)); // [(1, 1), (1, 2), (2, 1), (2, 2)]
System.out.println(Arrays.binarySearch(a, new Pair(1, 1), c)); // 0
System.out.println(Arrays.binarySearch(a, new Pair(1, 2), c)); // 1
System.out.println(Arrays.binarySearch(a, new Pair(2, 1), c)); // 2
System.out.println(Arrays.binarySearch(a, new Pair(2, 2), c)); // 3
System.out.println(Arrays.binarySearch(a, new Pair(3, 3), c)); // -5
static int compare (boolean[] a, boolean[] b)
final boolean[] a = {false, true, false};
final boolean[] b = {true, false, true};
System.out.println(Arrays.compare(a, a)); // 0
System.out.println(Arrays.compare(a, b)); // -1
System.out.println(Arrays.compare(b, a)); // 1
final boolean[] a = {true, true, true};
final boolean[] b = {true, true};
System.out.println(Arrays.compare(a, b)); // 1
System.out.println(Arrays.compare(b, a)); // -1
final boolean[] a = {false, false, false};
final boolean[] b = {true, true};
System.out.println(Arrays.compare(a, b)); // -1
System.out.println(Arrays.compare(b, a)); // 1
static int compare (boolean[] a, int aFromIndex, int aToIndex, boolean[] b, int bFromIndex, int bToIndex)
final boolean[] a = {true, true, false, false, true, true};
final boolean[] b = {false, false, true, true, false, false};
{
System.out.println(Arrays.compare(a, 0, 6, a, 0, 6)); // 0
System.out.println(Arrays.compare(a, 0, 6, b, 0, 6)); // 1
System.out.println(Arrays.compare(b, 0, 6, a, 0, 6)); // -1
}
{
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 0, 4))); // [true, true, false, false]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 2, 6))); // [true, true, false, false]
System.out.println(Arrays.compare(a, 0, 4, b, 2, 6)); // 0
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 2, 4))); // [false, false]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 0, 2))); // [false, false]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 4, 6))); // [false, false]
System.out.println(Arrays.compare(a, 2, 4, b, 0, 2)); // 0
System.out.println(Arrays.compare(a, 2, 4, b, 4, 6)); // 0
}
static int compare (byte[] a, byte[] b)
型が違うこと以外は、compare(int[] a, int[] b)と使い方は同じです。
API使用例はそちらをご参照ください。
static int compare (byte[] a, int aFromIndex, int aToIndex, byte[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、compare(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static int compare (char[] a, char[] b)
final char[] a = {'a', 'b', 'c', 'd', 'e', 'f'};
final char[] b = {'c', 'd', 'e', 'f', 'a', 'b'};
System.out.println(Arrays.compare(a, a)); // 0
System.out.println(Arrays.compare(a, b)); // -2
System.out.println(Arrays.compare(b, a)); // 2
final char[] a = {'a', 'a', 'a'};
final char[] b = {'a', 'a'};
System.out.println(Arrays.compare(a, b)); // 1
System.out.println(Arrays.compare(b, a)); // -1
final char[] a = {'a', 'a', 'a'};
final char[] b = {'b', 'b'};
System.out.println(Arrays.compare(a, b)); // -1
System.out.println(Arrays.compare(b, a)); // 1
static int compare (char[] a, int aFromIndex, int aToIndex, char[] b, int bFromIndex, int bToIndex)
final char[] a = {'a', 'b', 'c', 'd', 'e', 'f'};
final char[] b = {'c', 'd', 'e', 'f', 'a', 'b'};
System.out.println(Arrays.compare(a, 0, 6, a, 0, 6)); // 0
System.out.println(Arrays.compare(a, 0, 6, b, 0, 6)); // -2
System.out.println(Arrays.compare(b, 0, 6, a, 0, 6)); // 2
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 2, 6))); // [c, d, e, f]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 0, 4))); // [c, d, e, f]
System.out.println(Arrays.compare(a, 2, 6, b, 0, 4)); // 0
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 0, 2))); // [a, b]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 4, 6))); // [a, b]
System.out.println(Arrays.compare(a, 0, 2, b, 4, 6)); // 0
static int compare (double[] a, double[] b)
型が違うこと以外は、compare(int[] a, int[] b)と使い方は同じです。
API使用例はそちらをご参照ください。
static int compare (double[] a, int aFromIndex, int aToIndex, double[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、compare(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static int compare (float[] a, float[] b)
型が違うこと以外は、compare(int[] a, int[] b)と使い方は同じです。
API使用例はそちらをご参照ください。
static int compare (float[] a, int aFromIndex, int aToIndex, float[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、compare(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static int compare (int[] a, int[] b)
final int[] a = {0, 1, 2, 3, 4, 5};
final int[] b = {2, 3, 4, 5, 0, 1};
System.out.println(Arrays.compare(a, a)); // 0
System.out.println(Arrays.compare(a, b)); // -1
System.out.println(Arrays.compare(b, a)); // 1
final int[] a = {1, 1, 1};
final int[] b = {1, 1};
System.out.println(Arrays.compare(a, b)); // 1
System.out.println(Arrays.compare(b, a)); // -1
final int[] a = {0, 0, 0};
final int[] b = {1, 1};
System.out.println(Arrays.compare(a, b)); // -1
System.out.println(Arrays.compare(b, a)); // 1
static int compare (int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)
final int[] a = {0, 1, 2, 3, 4, 5};
final int[] b = {2, 3, 4, 5, 0, 1};
System.out.println(Arrays.compare(a, 0, 6, a, 0, 6)); // 0
System.out.println(Arrays.compare(a, 0, 6, b, 0, 6)); // -1
System.out.println(Arrays.compare(b, 0, 6, a, 0, 6)); // 1
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 2, 6))); // [2, 3, 4, 5]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 0, 4))); // [2, 3, 4, 5]
System.out.println(Arrays.compare(a, 2, 6, b, 0, 4)); // 0
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 0, 2))); // [0, 1]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 4, 6))); // [0, 1]
System.out.println(Arrays.compare(a, 0, 2, b, 4, 6)); // 0
static int compare (long[] a, int aFromIndex, int aToIndex, long[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、compare(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static int compare (long[] a, long[] b)
型が違うこと以外は、compare(int[] a, int[] b)と使い方は同じです。
API使用例はそちらをご参照ください。
static int compare (short[] a, int aFromIndex, int aToIndex, short[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、compare(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static int compare (short[] a, short[] b)
型が違うこと以外は、compare(int[] a, int[] b)と使い方は同じです。
API使用例はそちらをご参照ください。
static <T extends Comparable<? super T>> int compare (T[] a, int aFromIndex, int aToIndex, T[] b, int bFromIndex, int bToIndex)
// StringクラスはComparableを実装しています。
final String[] a = {"aa", "bb", "cc", "dd", "ee", "ff"};
final String[] b = {"cc", "dd", "ee", "ff", "aa", "bb"};
System.out.println(Arrays.compare(a, 0, 6, a, 0, 6)); // 0
System.out.println(Arrays.compare(a, 0, 6, b, 0, 6)); // -2
System.out.println(Arrays.compare(b, 0, 6, a, 0, 6)); // 2
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 2, 6))); // [cc, dd, ee, ff]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 0, 4))); // [cc, dd, ee, ff]
System.out.println(Arrays.compare(a, 2, 6, b, 0, 4)); // 0
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 0, 2))); // [aa, bb]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 4, 6))); // [aa, bb]
System.out.println(Arrays.compare(a, 0, 2, b, 4, 6)); // 0
static <T> int compare (T[] a, int aFromIndex, int aToIndex, T[] b, int bFromIndex, int bToIndex, Comparator<? super T> cmp)
PairとPairComparatorについてはこちらをご参照ください。
final Pair[] a = {
new Pair(0, 0), new Pair(0, 1), new Pair(0, 2),
new Pair(1, 0), new Pair(1, 1), new Pair(1, 2)};
final Pair[] b = {
new Pair(0, 2), new Pair(1, 0), new Pair(1, 1),
new Pair(1, 2), new Pair(0, 0), new Pair(0, 1)};
final var cmp = new PairComparator();
System.out.println(Arrays.compare(a, 0, 6, a, 0, 6, cmp)); // 0
System.out.println(Arrays.compare(a, 0, 6, b, 0, 6, cmp)); // -2
System.out.println(Arrays.compare(b, 0, 6, a, 0, 6, cmp)); // 2
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 2, 6))); // [(0, 2), (1, 0), (1, 1), (1, 2)]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 0, 4))); // [(0, 2), (1, 0), (1, 1), (1, 2)]
System.out.println(Arrays.compare(a, 2, 6, b, 0, 4, cmp)); // 0
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 0, 2))); // [(0, 0), (0, 1)]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 4, 6))); // [(0, 0), (0, 1)]
System.out.println(Arrays.compare(a, 0, 2, b, 4, 6, cmp)); // 0
static <T extends Comparable<? super T>> int compare (T[] a, T[] b)
// StringクラスはComparableを実装しています。
final String[] a = {"aa", "bb", "cc", "dd", "ee", "ff"};
final String[] b = {"cc", "dd", "ee", "ff", "aa", "bb"};
System.out.println(Arrays.compare(a, a)); // 0
System.out.println(Arrays.compare(a, b)); // -2
System.out.println(Arrays.compare(b, a)); // 2
final String[] a = {"aa", "aa", "aa"};
final String[] b = {"aa", "aa"};
System.out.println(Arrays.compare(a, b)); // 1
System.out.println(Arrays.compare(b, a)); // -1
final String[] a = {"aa", "aa", "aa"};
final String[] b = {"bb", "bb"};
System.out.println(Arrays.compare(a, b)); // -1
System.out.println(Arrays.compare(b, a)); // 1
static <T> int compare (T[] a, T[] b, Comparator<? super T> cmp)
PairとPairComparatorについてはこちらをご参照ください。
final Pair[] a = {
new Pair(0, 0), new Pair(0, 1), new Pair(0, 2),
new Pair(1, 0), new Pair(1, 1), new Pair(1, 2)};
final Pair[] b = {
new Pair(0, 2), new Pair(1, 0), new Pair(1, 1),
new Pair(1, 2), new Pair(0, 0), new Pair(0, 1)};
final var cmp = new PairComparator();
System.out.println(Arrays.compare(a, a, cmp)); // 0
System.out.println(Arrays.compare(a, b, cmp)); // -2
System.out.println(Arrays.compare(b, a, cmp)); // 2
final Pair[] a = {new Pair(0, 0), new Pair(0, 0), new Pair(0, 0)};
final Pair[] b = {new Pair(0, 0), new Pair(0, 0)};
final var cmp = new PairComparator();
System.out.println(Arrays.compare(a, b, cmp)); // 1
System.out.println(Arrays.compare(b, a, cmp)); // -1
final Pair[] a = {new Pair(0, 0), new Pair(0, 0), new Pair(0, 0)};
final Pair[] b = {new Pair(0, 1), new Pair(0, 1)};
final var cmp = new PairComparator();
System.out.println(Arrays.compare(a, b, cmp)); // -1
System.out.println(Arrays.compare(b, a, cmp)); // 1
static int compareUnsigned (byte[] a, byte[] b)
型が違うこと以外は、compareUnsigned(int[] a, int[] b)と使い方は同じです。
API使用例はそちらをご参照ください。
static int compareUnsigned (byte[] a, int aFromIndex, int aToIndex, byte[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、compareUnsigned(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static int compareUnsigned (int[] a, int[] b)
要素をunsignedとして扱う以外は compare(int[] a, int[] b) と同じになります。
API使用例はそちらもご参照ください。
final int[] a = {1, 1, 1};
final int[] b = {-1, -1, -1};
// -1は正の数の0xffffffffとして比較します。
System.out.println(Arrays.compareUnsigned(a, b)); // -1
// -1は負数として比較します。
System.out.println(Arrays.compare(a, b)); // 1
static int compareUnsigned (int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)
要素をunsignedとして扱う以外は compare(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex) と同じになります。
API使用例はそちらもご参照ください。
final int[] a = {1, 1, 1};
final int[] b = {-1, -1, -1};
// -1 は正の数の0xffffffffとして比較します。
System.out.println(Arrays.compareUnsigned(a, 0, 3, b, 0, 3)); // -1
// -1 は負数として比較します。
System.out.println(Arrays.compare(a, 0, 3, b, 0, 3)); // 1
static int compareUnsigned (long[] a, int aFromIndex, int aToIndex, long[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、compareUnsigned(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static int compareUnsigned (long[] a, long[] b)
型が違うこと以外は、compareUnsigned(int[] a, int[] b)と使い方は同じです。
API使用例はそちらをご参照ください。
static int compareUnsigned (short[] a, int aFromIndex, int aToIndex, short[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、compareUnsigned(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static int compareUnsigned (short[] a, short[] b)
型が違うこと以外は、compareUnsigned(int[] a, int[] b)と使い方は同じです。
API使用例はそちらをご参照ください。
static boolean[] copyOf (boolean[] original, int newLength)
final boolean[] original = {true, false, true, false};
System.out.println(Arrays.toString(original)); // [true, false, true, false]
final boolean[] copy1 = Arrays.copyOf(original, 4);
System.out.println(Arrays.toString(copy1)); // [true, false, true, false]
final boolean[] copy2 = Arrays.copyOf(original, 3);
System.out.println(Arrays.toString(copy2)); // [true, false, true]
final boolean[] copy3 = Arrays.copyOf(original, 2);
System.out.println(Arrays.toString(copy3)); // [true, false]
final boolean[] copy4 = Arrays.copyOf(original, 6);
System.out.println(Arrays.toString(copy4)); // [true, false, true, false, false, false]
static byte[] copyOf (byte[] original, int newLength)
型が違うこと以外は、copyOf(int[] original, int newLength)と使い方は同じです。
API使用例はそちらをご参照ください。
static char[] copyOf (char[] original, int newLength)
final char[] original = {'a', 'b', 'c', 'd'};
System.out.println(Arrays.toString(original)); // [a, b, c, d]
final char[] copy1 = Arrays.copyOf(original, 4);
System.out.println(Arrays.toString(copy1)); // [a, b, c, d]
final char[] copy2 = Arrays.copyOf(original, 3);
System.out.println(Arrays.toString(copy2)); // [a, b, c]
final char[] copy3 = Arrays.copyOf(original, 2);
System.out.println(Arrays.toString(copy3)); // [a, b]
final char[] copy4 = Arrays.copyOf(original, 6);
System.out.println(Arrays.toString(copy4)); // [a, b, c, d, , ]
static double[] copyOf (double[] original, int newLength)
型が違うこと以外は、copyOf(int[] original, int newLength)と使い方は同じです。
API使用例はそちらをご参照ください。
static float[] copyOf (float[] original, int newLength)
型が違うこと以外は、copyOf(int[] original, int newLength)と使い方は同じです。
API使用例はそちらをご参照ください。
static int[] copyOf (int[] original, int newLength)
final int[] original = {1, 2, 3, 4};
System.out.println(Arrays.toString(original)); // [1, 2, 3, 4]
final int[] copy1 = Arrays.copyOf(original, 4);
System.out.println(Arrays.toString(copy1)); // [1, 2, 3, 4]
final int[] copy2 = Arrays.copyOf(original, 3);
System.out.println(Arrays.toString(copy2)); // [1, 2, 3]
final int[] copy3 = Arrays.copyOf(original, 2);
System.out.println(Arrays.toString(copy3)); // [1, 2]
final int[] copy4 = Arrays.copyOf(original, 6);
System.out.println(Arrays.toString(copy4)); // [1, 2, 3, 4, 0, 0]
static long[] copyOf (long[] original, int newLength)
型が違うこと以外は、copyOf(int[] original, int newLength)と使い方は同じです。
API使用例はそちらをご参照ください。
static short[] copyOf (short[] original, int newLength)
型が違うこと以外は、copyOf(int[] original, int newLength)と使い方は同じです。
API使用例はそちらをご参照ください。
static <T> T[] copyOf (T[] original, int newLength)
final String[] original = {"aa", "bb", "cc", "dd"};
System.out.println(Arrays.toString(original)); // [aa, bb, cc, dd]
final String[] copy1 = Arrays.copyOf(original, 4);
System.out.println(Arrays.toString(copy1)); // [aa, bb, cc, dd]
final String[] copy2 = Arrays.copyOf(original, 3);
System.out.println(Arrays.toString(copy2)); // [aa, bb, cc]
final String[] copy3 = Arrays.copyOf(original, 2);
System.out.println(Arrays.toString(copy3)); // [aa, bb]
final String[] copy4 = Arrays.copyOf(original, 6);
System.out.println(Arrays.toString(copy4)); // [aa, bb, cc, dd, null, null]
static <T, U> T[] copyOf (U[] original, int newLength, Class<? extends T[]> newType)
final CharSequence[] original = {"aa", "bb", "cc", "dd"};
System.out.println(Arrays.toString(original)); // [aa, bb, cc, dd]
final String[] copy1 = Arrays.copyOf(original, 4, String[].class);
System.out.println(Arrays.toString(copy1)); // [aa, bb, cc, dd]
final String[] copy2 = Arrays.copyOf(original, 3, String[].class);
System.out.println(Arrays.toString(copy2)); // [aa, bb, cc]
final String[] copy3 = Arrays.copyOf(original, 2, String[].class);
System.out.println(Arrays.toString(copy3)); // [aa, bb]
final String[] copy4 = Arrays.copyOf(original, 6, String[].class);
System.out.println(Arrays.toString(copy4)); // [aa, bb, cc, dd, null, null]
static boolean[] copyOfRange (boolean[] original, int from, int to)
final boolean[] original = {true, false, true, false};
System.out.println(Arrays.toString(original)); // [true, false, true, false]
final boolean[] copy1 = Arrays.copyOfRange(original, 0, 4);
System.out.println(Arrays.toString(copy1)); // [true, false, true, false]
final boolean[] copy2 = Arrays.copyOfRange(original, 0, 3);
System.out.println(Arrays.toString(copy2)); // [true, false, true]
final boolean[] copy3 = Arrays.copyOfRange(original, 0, 2);
System.out.println(Arrays.toString(copy3)); // [true, false]
final boolean[] copy4 = Arrays.copyOfRange(original, 0, 6);
System.out.println(Arrays.toString(copy4)); // [true, false, true, false, false, false]
final boolean[] copy5 = Arrays.copyOfRange(original, 1, 4);
System.out.println(Arrays.toString(copy5)); // [false, true, false]
final boolean[] copy6 = Arrays.copyOfRange(original, 2, 4);
System.out.println(Arrays.toString(copy6)); // [true, false]
static byte[] copyOfRange (byte[] original, int from, int to)
型が違うこと以外は、copyOfRange(int[] original, int from, int to)と使い方は同じです。
API使用例はそちらをご参照ください。
static char[] copyOfRange (char[] original, int from, int to)
final char[] original = {'a', 'b', 'c', 'd'};
System.out.println(Arrays.toString(original)); // [a, b, c, d]
final char[] copy1 = Arrays.copyOfRange(original, 0, 4);
System.out.println(Arrays.toString(copy1)); // [a, b, c, d]
final char[] copy2 = Arrays.copyOfRange(original, 0, 3);
System.out.println(Arrays.toString(copy2)); // [a, b, c]
final char[] copy3 = Arrays.copyOfRange(original, 0, 2);
System.out.println(Arrays.toString(copy3)); // [a, b]
final char[] copy4 = Arrays.copyOfRange(original, 0, 6);
System.out.println(Arrays.toString(copy4)); // [a, b, c, d, , ]
final char[] copy5 = Arrays.copyOfRange(original, 1, 4);
System.out.println(Arrays.toString(copy5)); // [b, c, d]
final char[] copy6 = Arrays.copyOfRange(original, 2, 4);
System.out.println(Arrays.toString(copy6)); // [c, d]
static double[] copyOfRange (double[] original, int from, int to)
型が違うこと以外は、copyOfRange(int[] original, int from, int to)と使い方は同じです。
API使用例はそちらをご参照ください。
static float[] copyOfRange (float[] original, int from, int to)
型が違うこと以外は、copyOfRange(int[] original, int from, int to)と使い方は同じです。
API使用例はそちらをご参照ください。
static int[] copyOfRange (int[] original, int from, int to)
final int[] original = {1, 2, 3, 4};
System.out.println(Arrays.toString(original)); // [1, 2, 3, 4]
final int[] copy1 = Arrays.copyOfRange(original, 0, 4);
System.out.println(Arrays.toString(copy1)); // [1, 2, 3, 4]
final int[] copy2 = Arrays.copyOfRange(original, 0, 3);
System.out.println(Arrays.toString(copy2)); // [1, 2, 3]
final int[] copy3 = Arrays.copyOfRange(original, 0, 2);
System.out.println(Arrays.toString(copy3)); // [1, 2]
final int[] copy4 = Arrays.copyOfRange(original, 0, 6);
System.out.println(Arrays.toString(copy4)); // [1, 2, 3, 4, 0, 0]
final int[] copy5 = Arrays.copyOfRange(original, 1, 4);
System.out.println(Arrays.toString(copy5)); // [2, 3, 4]
final int[] copy6 = Arrays.copyOfRange(original, 2, 4);
System.out.println(Arrays.toString(copy6)); // [3, 4]
static long[] copyOfRange (long[] original, int from, int to)
型が違うこと以外は、copyOfRange(int[] original, int from, int to)と使い方は同じです。
API使用例はそちらをご参照ください。
static short[] copyOfRange (short[] original, int from, int to)
型が違うこと以外は、copyOfRange(int[] original, int from, int to)と使い方は同じです。
API使用例はそちらをご参照ください。
static <T> T[] copyOfRange (T[] original, int from, int to)
final String[] original = {"aa", "bb", "cc", "dd"};
System.out.println(Arrays.toString(original)); // [aa, bb, cc, dd]
final String[] copy1 = Arrays.copyOfRange(original, 0, 4);
System.out.println(Arrays.toString(copy1)); // [aa, bb, cc, dd]
final String[] copy2 = Arrays.copyOfRange(original, 0, 3);
System.out.println(Arrays.toString(copy2)); // [aa, bb, cc]
final String[] copy3 = Arrays.copyOfRange(original, 0, 2);
System.out.println(Arrays.toString(copy3)); // [aa, bb]
final String[] copy4 = Arrays.copyOfRange(original, 0, 6);
System.out.println(Arrays.toString(copy4)); // [aa, bb, cc, dd, null, null]
final String[] copy5 = Arrays.copyOfRange(original, 1, 4);
System.out.println(Arrays.toString(copy5)); // [bb, cc, dd]
final String[] copy6 = Arrays.copyOfRange(original, 2, 4);
System.out.println(Arrays.toString(copy6)); // [cc, dd]
static <T, U> T[] copyOfRange (U[] original, int from, int to, Class<? extends T[]> newType)
final CharSequence[] original = {"aa", "bb", "cc", "dd"};
System.out.println(Arrays.toString(original)); // [aa, bb, cc, dd]
final String[] copy1 = Arrays.copyOfRange(original, 0, 4, String[].class);
System.out.println(Arrays.toString(copy1)); // [aa, bb, cc, dd]
final String[] copy2 = Arrays.copyOfRange(original, 0, 3, String[].class);
System.out.println(Arrays.toString(copy2)); // [aa, bb, cc]
final String[] copy3 = Arrays.copyOfRange(original, 0, 2, String[].class);
System.out.println(Arrays.toString(copy3)); // [aa, bb]
final String[] copy4 = Arrays.copyOfRange(original, 0, 6, String[].class);
System.out.println(Arrays.toString(copy4)); // [aa, bb, cc, dd, null, null]
final String[] copy5 = Arrays.copyOfRange(original, 1, 4, String[].class);
System.out.println(Arrays.toString(copy5)); // [bb, cc, dd]
final String[] copy6 = Arrays.copyOfRange(original, 2, 4, String[].class);
System.out.println(Arrays.toString(copy6)); // [cc, dd]
static boolean deepEquals (Object[] a1, Object[] a2)
final int[][] a = {{1, 2}, {3, 4}, {5, 6}};
System.out.println(Arrays.deepToString(a)); // [[1, 2], [3, 4], [5, 6]]
final int[][] b = {{1, 2}, {3, 4}, {5, 6}};
System.out.println(Arrays.deepToString(b)); // [[1, 2], [3, 4], [5, 6]]
System.out.println(Arrays.deepEquals(a, b)); // true
System.out.println(Arrays.equals(a, b)); // false
final int[][] c = {{10, 20}, {30, 40}, {50, 60}};
System.out.println(Arrays.deepToString(c)); // [[10, 20], [30, 40], [50, 60]]
System.out.println(Arrays.deepEquals(a, c)); // false
static int deepHashCode (Object[] a)
final int[][] a = {{1, 2}, {3, 4}, {5, 6}};
System.out.println(Arrays.deepToString(a)); // [[1, 2], [3, 4], [5, 6]]
final int[][] b = {{1, 2}, {3, 4}, {5, 6}};
System.out.println(Arrays.deepToString(b)); // [[1, 2], [3, 4], [5, 6]]
System.out.println(Arrays.deepHashCode(a)); // 1018945
System.out.println(Arrays.deepHashCode(b)); // 1018945
System.out.println(Arrays.hashCode(a)); // 566646003
System.out.println(Arrays.hashCode(b)); // 1569176015
static String deepToString (Object[] a)
final int[][] a = {{1, 2}, {3, 4}, {5, 6}};
System.out.println(Arrays.deepToString(a)); // [[1, 2], [3, 4], [5, 6]]
System.out.println(Arrays.toString(a)); // [[I@60db1c0e, [I@3e78b6a5, [I@769a1df5]
static boolean equals (boolean[] a, boolean[] a2)
final boolean[] a = {true, true, true};
final boolean[] a2 = {true, true, true};
System.out.println(Arrays.equals(a, a2)); // true
final boolean[] a = {false, true, false};
final boolean[] a2 = {true, false, true};
System.out.println(Arrays.equals(a, a2)); // false
final boolean[] a = {true, true, true};
final boolean[] a2 = {true, true};
System.out.println(Arrays.equals(a, a2)); // false
static boolean equals (boolean[] a, int aFromIndex, int aToIndex, boolean[] b, int bFromIndex, int bToIndex)
final boolean[] a = {true, true, false, false, true, true};
final boolean[] b = {false, false, true, true, false, false};
System.out.println(Arrays.equals(a, 0, 6, b, 0, 6)); // false
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 0, 4))); // [true, true, false, false]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 2, 6))); // [true, true, false, false]
System.out.println(Arrays.equals(a, 0, 4, b, 2, 6)); // true
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 2, 4))); // [false, false]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 0, 2))); // [false, false]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 4, 6))); // [false, false]
System.out.println(Arrays.equals(a, 2, 4, b, 0, 2)); // true
System.out.println(Arrays.equals(a, 2, 4, b, 4, 6)); // true
static boolean equals (byte[] a, byte[] a2)
型が違うこと以外は、equals(int[] a, int[] a2)と使い方は同じです。
API使用例はそちらをご参照ください。
static boolean equals (byte[] a, int aFromIndex, int aToIndex, byte[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、equals(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static boolean equals (char[] a, char[] a2)
final char[] a = {'a', 'b', 'c', 'd', 'e', 'f'};
final char[] a2 = {'a', 'b', 'c', 'd', 'e', 'f'};
System.out.println(Arrays.equals(a, a2)); // true
final char[] a = {'a', 'b', 'c', 'd', 'e', 'f'};
final char[] a2 = {'c', 'd', 'e', 'f', 'a', 'b'};
System.out.println(Arrays.equals(a, a2)); // false
final char[] a = {'a', 'a', 'a'};
final char[] a2 = {'a', 'a'};
System.out.println(Arrays.equals(a, a2)); // false
static boolean equals (char[] a, int aFromIndex, int aToIndex, char[] b, int bFromIndex, int bToIndex)
final char[] a = {'a', 'b', 'c', 'd', 'e', 'f'};
final char[] b = {'c', 'd', 'e', 'f', 'a', 'b'};
System.out.println(Arrays.equals(a, 0, 6, b, 0, 6)); // false
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 2, 6))); // [c, d, e, f]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 0, 4))); // [c, d, e, f]
System.out.println(Arrays.equals(a, 2, 6, b, 0, 4)); // true
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 0, 2))); // [a, b]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 4, 6))); // [a, b]
System.out.println(Arrays.equals(a, 0, 2, b, 4, 6)); // true
static boolean equals (double[] a, double[] a2)
型が違うこと以外は、equals(int[] a, int[] a2)と使い方は同じです。
API使用例はそちらをご参照ください。
static boolean equals (double[] a, int aFromIndex, int aToIndex, double[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、equals(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static boolean equals (float[] a, float[] a2)
型が違うこと以外は、equals(int[] a, int[] a2)と使い方は同じです。
API使用例はそちらをご参照ください。
static boolean equals (float[] a, int aFromIndex, int aToIndex, float[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、equals(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static boolean equals (int[] a, int[] a2)
final int[] a = {0, 1, 2, 3, 4, 5};
final int[] a2 = {0, 1, 2, 3, 4, 5};
System.out.println(Arrays.equals(a, a2)); // true
final int[] a = {0, 1, 2, 3, 4, 5};
final int[] a2 = {2, 3, 4, 5, 0, 1};
System.out.println(Arrays.equals(a, a2)); // false
final int[] a = {1, 1, 1};
final int[] a2 = {1, 1};
System.out.println(Arrays.equals(a, a2)); // false
static boolean equals (int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)
final int[] a = {0, 1, 2, 3, 4, 5};
final int[] b = {2, 3, 4, 5, 0, 1};
System.out.println(Arrays.equals(a, 0, 6, b, 0, 6)); // false
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 2, 6))); // [2, 3, 4, 5]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 0, 4))); // [2, 3, 4, 5]
System.out.println(Arrays.equals(a, 2, 6, b, 0, 4)); // true
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 0, 2))); // [0, 1]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 4, 6))); // [0, 1]
System.out.println(Arrays.equals(a, 0, 2, b, 4, 6)); // true
static boolean equals (long[] a, int aFromIndex, int aToIndex, long[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、equals(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static boolean equals (long[] a, long[] a2)
型が違うこと以外は、equals(int[] a, int[] a2)と使い方は同じです。
API使用例はそちらをご参照ください。
static boolean equals (short[] a, int aFromIndex, int aToIndex, short[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、equals(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static boolean equals (short[] a, short[] a2)
型が違うこと以外は、equals(int[] a, int[] a2)と使い方は同じです。
API使用例はそちらをご参照ください。
static boolean equals (Object[] a, int aFromIndex, int aToIndex, Object[] b, int bFromIndex, int bToIndex)
final String[] a = {"aa", "bb", "cc", "dd", "ee", "ff"};
final String[] b = {"cc", "dd", "ee", "ff", "aa", "bb"};
System.out.println(Arrays.equals(a, 0, 6, b, 0, 6)); // false
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 2, 6))); // [cc, dd, ee, ff]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 0, 4))); // [cc, dd, ee, ff]
System.out.println(Arrays.equals(a, 2, 6, b, 0, 4)); // true
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 0, 2))); // [aa, bb]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 4, 6))); // [aa, bb]
System.out.println(Arrays.equals(a, 0, 2, b, 4, 6)); // true
static boolean equals (Object[] a, Object[] a2)
final String[] a = {"aa", "bb", "cc", "dd", "ee", "ff"};
final String[] a2 = {"aa", "bb", "cc", "dd", "ee", "ff"};
System.out.println(Arrays.equals(a, a2)); // true
final String[] a = {"aa", "bb", "cc", "dd", "ee", "ff"};
final String[] a2 = {"cc", "dd", "ee", "ff", "aa", "bb"};
System.out.println(Arrays.equals(a, a2)); // false
final String[] a = {"aa", "aa", "aa"};
final String[] a2 = {"aa", "aa"};
System.out.println(Arrays.equals(a, a2)); // false
static <T> boolean equals (T[] a, int aFromIndex, int aToIndex, T[] b, int bFromIndex, int bToIndex, Comparator<? super T> cmp)
PairとPairComparatorについてはこちらをご参照ください。
final Pair[] a = {
new Pair(0, 0), new Pair(0, 1), new Pair(0, 2),
new Pair(1, 0), new Pair(1, 1), new Pair(1, 2)};
final Pair[] b = {
new Pair(0, 2), new Pair(1, 0), new Pair(1, 1),
new Pair(1, 2), new Pair(0, 0), new Pair(0, 1)};
final var cmp = new PairComparator();
System.out.println(Arrays.equals(a, 0, 6, b, 0, 6, cmp)); // false
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 2, 6))); // [(0, 2), (1, 0), (1, 1), (1, 2)]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 0, 4))); // [(0, 2), (1, 0), (1, 1), (1, 2)]
System.out.println(Arrays.equals(a, 2, 6, b, 0, 4, cmp)); // true
System.out.println(Arrays.toString(Arrays.copyOfRange(a, 0, 2))); // [(0, 0), (0, 1)]
System.out.println(Arrays.toString(Arrays.copyOfRange(b, 4, 6))); // [(0, 0), (0, 1)]
System.out.println(Arrays.equals(a, 0, 2, b, 4, 6, cmp)); // true
static <T> boolean equals (T[] a, T[] a2, Comparator<? super T> cmp)
PairとPairComparatorについてはこちらをご参照ください。
final Pair[] a = {
new Pair(0, 0), new Pair(0, 1), new Pair(0, 2),
new Pair(1, 0), new Pair(1, 1), new Pair(1, 2)};
final Pair[] a2 = {
new Pair(0, 0), new Pair(0, 1), new Pair(0, 2),
new Pair(1, 0), new Pair(1, 1), new Pair(1, 2)};
final var cmp = new PairComparator();
System.out.println(Arrays.equals(a, a2, cmp)); // true
final Pair[] a = {
new Pair(0, 0), new Pair(0, 1), new Pair(0, 2),
new Pair(1, 0), new Pair(1, 1), new Pair(1, 2)};
final Pair[] a2 = {
new Pair(0, 2), new Pair(1, 0), new Pair(1, 1),
new Pair(1, 2), new Pair(0, 0), new Pair(0, 1)};
final var cmp = new PairComparator();
System.out.println(Arrays.equals(a, a2, cmp)); // false
final Pair[] a = {new Pair(0, 0), new Pair(0, 0), new Pair(0, 0)};
final Pair[] a2 = {new Pair(0, 0), new Pair(0, 0)};
final var cmp = new PairComparator();
System.out.println(Arrays.equals(a, a2, cmp)); // false
static void fill (boolean[] a, boolean val)
final var a = new boolean[5];
System.out.println(Arrays.toString(a)); // [false, false, false, false, false]
Arrays.fill(a, true);
System.out.println(Arrays.toString(a)); // [true, true, true, true, true]
static void fill (boolean[] a, int fromIndex, int toIndex, boolean val)
final var a1 = new boolean[4];
final var a2 = new boolean[4];
final var a3 = new boolean[4];
final var a4 = new boolean[4];
System.out.println(Arrays.toString(a1)); // [false, false, false, false]
Arrays.fill(a1, 0, 4, true);
Arrays.fill(a2, 0, 3, true);
Arrays.fill(a3, 0, 2, true);
Arrays.fill(a4, 0, 1, true);
System.out.println(Arrays.toString(a1)); // [true, true, true, true]
System.out.println(Arrays.toString(a2)); // [true, true, true, false]
System.out.println(Arrays.toString(a3)); // [true, true, false, false]
System.out.println(Arrays.toString(a4)); // [true, false, false, false]
final var a1 = new boolean[4];
final var a2 = new boolean[4];
final var a3 = new boolean[4];
final var a4 = new boolean[4];
System.out.println(Arrays.toString(a1)); // [false, false, false, false]
Arrays.fill(a1, 0, 4, true);
Arrays.fill(a2, 1, 4, true);
Arrays.fill(a3, 2, 4, true);
Arrays.fill(a4, 3, 4, true);
System.out.println(Arrays.toString(a1)); // [true, true, true, true]
System.out.println(Arrays.toString(a2)); // [false, true, true, true]
System.out.println(Arrays.toString(a3)); // [false, false, true, true]
System.out.println(Arrays.toString(a4)); // [false, false, false, true]
static void fill (byte[] a, byte val)
型が違うこと以外は、fill(int[] a, int val)と使い方は同じです。
API使用例はそちらをご参照ください。
static void fill (byte[] a, int fromIndex, int toIndex, byte val)
型が違うこと以外は、fill(int[] a, int fromIndex, int toIndex, int val)と使い方は同じです。
API使用例はそちらをご参照ください。
static void fill (char[] a, char val)
final var a = new char[5];
System.out.println(Arrays.toString(a)); // [ , , , , ]
Arrays.fill(a, 'a');
System.out.println(Arrays.toString(a)); // [a, a, a, a, a]
static void fill (char[] a, int fromIndex, int toIndex, char val)
final var a1 = new char[4];
final var a2 = new char[4];
final var a3 = new char[4];
final var a4 = new char[4];
System.out.println(Arrays.toString(a1)); // [ , , , ]
Arrays.fill(a1, 0, 4, 'a');
Arrays.fill(a2, 0, 3, 'a');
Arrays.fill(a3, 0, 2, 'a');
Arrays.fill(a4, 0, 1, 'a');
System.out.println(Arrays.toString(a1)); // [a, a, a, a]
System.out.println(Arrays.toString(a2)); // [a, a, a, ]
System.out.println(Arrays.toString(a3)); // [a, a, , ]
System.out.println(Arrays.toString(a4)); // [a, , , ]
final var a1 = new char[4];
final var a2 = new char[4];
final var a3 = new char[4];
final var a4 = new char[4];
System.out.println(Arrays.toString(a1)); // [ , , , ]
Arrays.fill(a1, 0, 4, 'a');
Arrays.fill(a2, 1, 4, 'a');
Arrays.fill(a3, 2, 4, 'a');
Arrays.fill(a4, 3, 4, 'a');
System.out.println(Arrays.toString(a1)); // [a, a, a, a]
System.out.println(Arrays.toString(a2)); // [ , a, a, a]
System.out.println(Arrays.toString(a3)); // [ , , a, a]
System.out.println(Arrays.toString(a4)); // [ , , , a]
static void fill (double[] a, double val)
型が違うこと以外は、fill(int[] a, int val)と使い方は同じです。
API使用例はそちらをご参照ください。
static void fill (double[] a, int fromIndex, int toIndex, double val)
型が違うこと以外は、fill(int[] a, int fromIndex, int toIndex, int val)と使い方は同じです。
API使用例はそちらをご参照ください。
static void fill (float[] a, float val)
型が違うこと以外は、fill(int[] a, int val)と使い方は同じです。
API使用例はそちらをご参照ください。
static void fill (float[] a, int fromIndex, int toIndex, float val)
型が違うこと以外は、fill(int[] a, int fromIndex, int toIndex, int val)と使い方は同じです。
API使用例はそちらをご参照ください。
static void fill (int[] a, int val)
final var a = new int[5];
System.out.println(Arrays.toString(a)); // [0, 0, 0, 0, 0]
Arrays.fill(a, 9);
System.out.println(Arrays.toString(a)); // [9, 9, 9, 9, 9]
static void fill (int[] a, int fromIndex, int toIndex, int val)
final var a1 = new int[4];
final var a2 = new int[4];
final var a3 = new int[4];
final var a4 = new int[4];
System.out.println(Arrays.toString(a1)); // [0, 0, 0, 0]
Arrays.fill(a1, 0, 4, 9);
Arrays.fill(a2, 0, 3, 9);
Arrays.fill(a3, 0, 2, 9);
Arrays.fill(a4, 0, 1, 9);
System.out.println(Arrays.toString(a1)); // [9, 9, 9, 9]
System.out.println(Arrays.toString(a2)); // [9, 9, 9, 0]
System.out.println(Arrays.toString(a3)); // [9, 9, 0, 0]
System.out.println(Arrays.toString(a4)); // [9, 0, 0, 0]
final var a1 = new int[4];
final var a2 = new int[4];
final var a3 = new int[4];
final var a4 = new int[4];
System.out.println(Arrays.toString(a1)); // [0, 0, 0, 0]
Arrays.fill(a1, 0, 4, 9);
Arrays.fill(a2, 1, 4, 9);
Arrays.fill(a3, 2, 4, 9);
Arrays.fill(a4, 3, 4, 9);
System.out.println(Arrays.toString(a1)); // [9, 9, 9, 9]
System.out.println(Arrays.toString(a2)); // [0, 9, 9, 9]
System.out.println(Arrays.toString(a3)); // [0, 0, 9, 9]
System.out.println(Arrays.toString(a4)); // [0, 0, 0, 9]
static void fill (long[] a, int fromIndex, int toIndex, long val)
型が違うこと以外は、fill(int[] a, int fromIndex, int toIndex, int val)と使い方は同じです。
API使用例はそちらをご参照ください。
static void fill (long[] a, long val)
型が違うこと以外は、fill(int[] a, int val)と使い方は同じです。
API使用例はそちらをご参照ください。
static void fill (short[] a, int fromIndex, int toIndex, short val)
型が違うこと以外は、fill(int[] a, int fromIndex, int toIndex, int val)と使い方は同じです。
API使用例はそちらをご参照ください。
static void fill (short[] a, short val)
型が違うこと以外は、fill(int[] a, int val)と使い方は同じです。
API使用例はそちらをご参照ください。
static void fill (Object[] a, int fromIndex, int toIndex, Object val)
final var a1 = new String[4];
final var a2 = new String[4];
final var a3 = new String[4];
final var a4 = new String[4];
System.out.println(Arrays.toString(a1)); // [null, null, null, null]
Arrays.fill(a1, 0, 4, "a");
Arrays.fill(a2, 0, 3, "a");
Arrays.fill(a3, 0, 2, "a");
Arrays.fill(a4, 0, 1, "a");
System.out.println(Arrays.toString(a1)); // [a, a, a, a]
System.out.println(Arrays.toString(a2)); // [a, a, a, null]
System.out.println(Arrays.toString(a3)); // [a, a, null, null]
System.out.println(Arrays.toString(a4)); // [a, null, null, null]
final var a1 = new String[4];
final var a2 = new String[4];
final var a3 = new String[4];
final var a4 = new String[4];
System.out.println(Arrays.toString(a1)); // [null, null, null, null]
Arrays.fill(a1, 0, 4, "a");
Arrays.fill(a2, 1, 4, "a");
Arrays.fill(a3, 2, 4, "a");
Arrays.fill(a4, 3, 4, "a");
System.out.println(Arrays.toString(a1)); // [a, a, a, a]
System.out.println(Arrays.toString(a2)); // [null, a, a, a]
System.out.println(Arrays.toString(a3)); // [null, null, a, a]
System.out.println(Arrays.toString(a4)); // [null, null, null, a]
static void fill (Object[] a, Object val)
final var a = new String[5];
System.out.println(Arrays.toString(a)); // [null, null, null, null, null]
Arrays.fill(a, "a");
System.out.println(Arrays.toString(a)); // [a, a, a, a, a]
static int hashCode (boolean[] a)
final boolean[] a1 = {true, false, true};
final boolean[] a2 = {true, false, true};
System.out.println(a1 != a2); // true
System.out.println(Arrays.hashCode(a1)); // 1252360
System.out.println(Arrays.hashCode(a2)); // 1252360
System.out.println(a1.hashCode()); // 964039755
System.out.println(a2.hashCode()); // 617590710
static int hashCode (byte[] a)
型が違うこと以外は、hashCode(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static int hashCode (char[] a)
final char[] a1 = {'a', 'b', 'c'};
final char[] a2 = {'a', 'b', 'c'};
System.out.println(a1 != a2); // true
System.out.println(Arrays.hashCode(a1)); // 126145
System.out.println(Arrays.hashCode(a2)); // 126145
System.out.println(a1.hashCode()); // 10241554
System.out.println(a2.hashCode()); // 741227068
static int hashCode (double[] a)
型が違うこと以外は、hashCode(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static int hashCode (float[] a)
型が違うこと以外は、hashCode(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static int hashCode (int[] a)
final char[] a1 = {1, 2, 3};
final char[] a2 = {1, 2, 3};
System.out.println(a1 != a2); // true
System.out.println(Arrays.hashCode(a1)); // 30817
System.out.println(Arrays.hashCode(a2)); // 30817
System.out.println(a1.hashCode()); // 636725182
System.out.println(a2.hashCode()); // 2081951401
static int hashCode (long[] a)
型が違うこと以外は、hashCode(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static int hashCode (short[] a)
型が違うこと以外は、hashCode(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static int hashCode (Object[] a)
final String[] a1 = {"aa", "bb", "cc"};
final String[] a2 = {"aa", "bb", "cc"};
System.out.println(a1 != a2); // true
System.out.println(Arrays.hashCode(a1)); // 3113119
System.out.println(Arrays.hashCode(a2)); // 3113119
System.out.println(a1.hashCode()); // 508984302
System.out.println(a2.hashCode()); // 1140084162
static int mismatch (boolean[] a, boolean[] b)
final boolean[] a = {true, true, true};
final boolean[] b1 = {false, false, false};
final boolean[] b2 = {true, false, false};
final boolean[] b3 = {true, true, false};
final boolean[] b4 = {true, true, true};
System.out.println(Arrays.mismatch(a, b1)); // 0
System.out.println(Arrays.mismatch(a, b2)); // 1
System.out.println(Arrays.mismatch(a, b3)); // 2
System.out.println(Arrays.mismatch(a, b4)); // -1
static int mismatch (boolean[] a, int aFromIndex, int aToIndex, boolean[] b, int bFromIndex, int bToIndex)
final boolean[] a = {true, true, true, false, false, false};
final boolean[] b = {true, true, true, true, true, true};
System.out.println(Arrays.mismatch(a, 0, 6, b, 0, 6)); // 3
System.out.println(Arrays.mismatch(a, 0, 5, b, 0, 5)); // 3
System.out.println(Arrays.mismatch(a, 0, 4, b, 0, 4)); // 3
System.out.println(Arrays.mismatch(a, 0, 3, b, 0, 3)); // -1
System.out.println(Arrays.mismatch(a, 1, 6, b, 1, 6)); // 2
System.out.println(Arrays.mismatch(a, 2, 6, b, 2, 6)); // 1
System.out.println(Arrays.mismatch(a, 3, 6, b, 3, 6)); // 0
static int mismatch (byte[] a, byte[] b)
型が違うこと以外は、mismatch(int[] a, int[] b)と使い方は同じです。
API使用例はそちらをご参照ください。
static int mismatch (byte[] a, int aFromIndex, int aToIndex, byte[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、mismatch(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static int mismatch (char[] a, char[] b)
final char[] a = {'a', 'b', 'c'};
final char[] b1 = {'z', 'b', 'c'};
final char[] b2 = {'a', 'z', 'c'};
final char[] b3 = {'a', 'b', 'z'};
final char[] b4 = {'a', 'b', 'c'};
System.out.println(Arrays.mismatch(a, b1)); // 0
System.out.println(Arrays.mismatch(a, b2)); // 1
System.out.println(Arrays.mismatch(a, b3)); // 2
System.out.println(Arrays.mismatch(a, b4)); // -1
static int mismatch (char[] a, int aFromIndex, int aToIndex, char[] b, int bFromIndex, int bToIndex)
final char[] a = {'a', 'b', 'c', 'd', 'e', 'f'};
final char[] b = {'a', 'b', 'c', 'x', 'y', 'z'};
System.out.println(Arrays.mismatch(a, 0, 6, b, 0, 6)); // 3
System.out.println(Arrays.mismatch(a, 0, 5, b, 0, 5)); // 3
System.out.println(Arrays.mismatch(a, 0, 4, b, 0, 4)); // 3
System.out.println(Arrays.mismatch(a, 0, 3, b, 0, 3)); // -1
System.out.println(Arrays.mismatch(a, 1, 6, b, 1, 6)); // 2
System.out.println(Arrays.mismatch(a, 2, 6, b, 2, 6)); // 1
System.out.println(Arrays.mismatch(a, 3, 6, b, 3, 6)); // 0
static int mismatch (double[] a, double[] b)
型が違うこと以外は、mismatch(int[] a, int[] b)と使い方は同じです。
API使用例はそちらをご参照ください。
static int mismatch (double[] a, int aFromIndex, int aToIndex, double[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、mismatch(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static int mismatch (float[] a, float[] b)
型が違うこと以外は、mismatch(int[] a, int[] b)と使い方は同じです。
API使用例はそちらをご参照ください。
static int mismatch (float[] a, int aFromIndex, int aToIndex, float[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、mismatch(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static int mismatch (int[] a, int[] b)
final int[] a = {0, 1, 2};
final int[] b1 = {9, 1, 2};
final int[] b2 = {0, 9, 2};
final int[] b3 = {0, 1, 9};
final int[] b4 = {0, 1, 2};
System.out.println(Arrays.mismatch(a, b1)); // 0
System.out.println(Arrays.mismatch(a, b2)); // 1
System.out.println(Arrays.mismatch(a, b3)); // 2
System.out.println(Arrays.mismatch(a, b4)); // -1
static int mismatch (int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)
final int[] a = {0, 1, 2, 3, 4, 5};
final int[] b = {0, 1, 2, 30, 40, 50};
System.out.println(Arrays.mismatch(a, 0, 6, b, 0, 6)); // 3
System.out.println(Arrays.mismatch(a, 0, 5, b, 0, 5)); // 3
System.out.println(Arrays.mismatch(a, 0, 4, b, 0, 4)); // 3
System.out.println(Arrays.mismatch(a, 0, 3, b, 0, 3)); // -1
System.out.println(Arrays.mismatch(a, 1, 6, b, 1, 6)); // 2
System.out.println(Arrays.mismatch(a, 2, 6, b, 2, 6)); // 1
System.out.println(Arrays.mismatch(a, 3, 6, b, 3, 6)); // 0
static int mismatch (long[] a, int aFromIndex, int aToIndex, long[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、mismatch(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static int mismatch (long[] a, long[] b)
型が違うこと以外は、mismatch(int[] a, int[] b)と使い方は同じです。
API使用例はそちらをご参照ください。
static int mismatch (short[] a, int aFromIndex, int aToIndex, short[] b, int bFromIndex, int bToIndex)
型が違うこと以外は、mismatch(int[] a, int aFromIndex, int aToIndex, int[] b, int bFromIndex, int bToIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static int mismatch (short[] a, short[] b)
型が違うこと以外は、mismatch(int[] a, int[] b)と使い方は同じです。
API使用例はそちらをご参照ください。
static int mismatch (Object[] a, int aFromIndex, int aToIndex, Object[] b, int bFromIndex, int bToIndex)
final String[] a = {"a", "b", "c", "d", "e", "f"};
final String[] b = {"a", "b", "c", "x", "y", "z"};
System.out.println(Arrays.mismatch(a, 0, 6, b, 0, 6)); // 3
System.out.println(Arrays.mismatch(a, 0, 5, b, 0, 5)); // 3
System.out.println(Arrays.mismatch(a, 0, 4, b, 0, 4)); // 3
System.out.println(Arrays.mismatch(a, 0, 3, b, 0, 3)); // -1
System.out.println(Arrays.mismatch(a, 1, 6, b, 1, 6)); // 2
System.out.println(Arrays.mismatch(a, 2, 6, b, 2, 6)); // 1
System.out.println(Arrays.mismatch(a, 3, 6, b, 3, 6)); // 0
static int mismatch (Object[] a, Object[] b)
final String[] a = {"a", "b", "c"};
final String[] b1 = {"z", "b", "c"};
final String[] b2 = {"a", "z", "c"};
final String[] b3 = {"a", "b", "z"};
final String[] b4 = {"a", "b", "c"};
System.out.println(Arrays.mismatch(a, b1)); // 0
System.out.println(Arrays.mismatch(a, b2)); // 1
System.out.println(Arrays.mismatch(a, b3)); // 2
System.out.println(Arrays.mismatch(a, b4)); // -1
static <T> int mismatch (T[] a, int aFromIndex, int aToIndex, T[] b, int bFromIndex, int bToIndex, Comparator<? super T> cmp)
PairとPairComparatorについてはこちらをご参照ください。
final Pair[] a = {
new Pair(0, 1), new Pair(0, 2), new Pair(0, 3),
new Pair(0, 4), new Pair(0, 5), new Pair(0, 6)};
final Pair[] b = {
new Pair(0, 1), new Pair(0, 2), new Pair(0, 3),
new Pair(1, 1), new Pair(1, 2), new Pair(1, 3)};
final var cmp = new PairComparator();
System.out.println(Arrays.mismatch(a, 0, 6, b, 0, 6, cmp)); // 3
System.out.println(Arrays.mismatch(a, 0, 5, b, 0, 5, cmp)); // 3
System.out.println(Arrays.mismatch(a, 0, 4, b, 0, 4, cmp)); // 3
System.out.println(Arrays.mismatch(a, 0, 3, b, 0, 3, cmp)); // -1
System.out.println(Arrays.mismatch(a, 1, 6, b, 1, 6, cmp)); // 2
System.out.println(Arrays.mismatch(a, 2, 6, b, 2, 6, cmp)); // 1
System.out.println(Arrays.mismatch(a, 3, 6, b, 3, 6, cmp)); // 0
static <T> int mismatch (T[] a, T[] b, Comparator<? super T> cmp)
PairとPairComparatorについてはこちらをご参照ください。
final Pair[] a = {new Pair(0, 1), new Pair(0, 2), new Pair(0, 3)};
final Pair[] b1 = {new Pair(9, 9), new Pair(0, 2), new Pair(0, 3)};
final Pair[] b2 = {new Pair(0, 1), new Pair(9, 9), new Pair(0, 3)};
final Pair[] b3 = {new Pair(0, 1), new Pair(0, 2), new Pair(9, 9)};
final Pair[] b4 = {new Pair(0, 1), new Pair(0, 2), new Pair(0, 3)};
final var cmp = new PairComparator();
System.out.println(Arrays.mismatch(a, b1, cmp)); // 0
System.out.println(Arrays.mismatch(a, b2, cmp)); // 1
System.out.println(Arrays.mismatch(a, b3, cmp)); // 2
System.out.println(Arrays.mismatch(a, b4, cmp)); // -1
static void parallelPrefix (double[] array, int fromIndex, int toIndex, DoubleBinaryOperator op)
型が違うこと以外は、parallelPrefix(int[] array, int fromIndex, int toIndex, IntBinaryOperator op)と使い方は同じです。
API使用例はそちらをご参照ください。
static void parallelPrefix (double[] array, DoubleBinaryOperator op)
型が違うこと以外は、parallelPrefix(int[] array, IntBinaryOperator op)と使い方は同じです。
API使用例はそちらをご参照ください。
static void parallelPrefix (int[] array, int fromIndex, int toIndex, IntBinaryOperator op)
final int[] array = {1, 2, 3, 4, 5, 6};
System.out.println("array : " + Arrays.toString(Arrays.copyOfRange(array, 2, 5)));
Arrays.parallelPrefix(array, 2, 5, (left, right) -> {
System.out.println("left = %d : right = %d".formatted(left, right));
return left + right;
});
System.out.println("array : " + Arrays.toString(array));
// 結果
// ↓
//array : [3, 4, 5]
//left = 3 : right = 4
//left = 7 : right = 5
//array : [1, 2, 3, 7, 12, 6]
static void parallelPrefix (int[] array, IntBinaryOperator op)
final int[] array = {1, 2, 3, 4};
Arrays.parallelPrefix(array, (left, right) -> {
System.out.println("left = %d : right = %d".formatted(left, right));
return left + right;
});
System.out.println("array : " + Arrays.toString(array));
// 結果
// ↓
//left = 1 : right = 2
//left = 3 : right = 3
//left = 6 : right = 4
//array : [1, 3, 6, 10]
static void parallelPrefix (long[] array, int fromIndex, int toIndex, LongBinaryOperator op)
型が違うこと以外は、parallelPrefix(int[] array, int fromIndex, int toIndex, IntBinaryOperator op)と使い方は同じです。
API使用例はそちらをご参照ください。
static void parallelPrefix (long[] array, LongBinaryOperator op)
型が違うこと以外は、parallelPrefix(int[] array, IntBinaryOperator op)と使い方は同じです。
API使用例はそちらをご参照ください。
static <T> void parallelPrefix (T[] array, int fromIndex, int toIndex, BinaryOperator<T> op)
final String[] array = {"a", "b", "c", "d", "e", "f"};
System.out.println("array : " + Arrays.toString(Arrays.copyOfRange(array, 2, 5)));
Arrays.parallelPrefix(array, 2, 5, (left, right) -> {
System.out.println("left = %s : right = %s".formatted(left, right));
return left + right;
});
System.out.println("array : " + Arrays.toString(array));
// 結果
// ↓
//array : [c, d, e]
//left = c : right = d
//left = cd : right = e
//array : [a, b, c, cd, cde, f]
static <T> void parallelPrefix (T[] array, BinaryOperator<T> op)
final String[] array = {"a", "b", "c", "d"};
Arrays.parallelPrefix(array, (left, right) -> {
System.out.println("left = %s : right = %s".formatted(left, right));
return left + right;
});
System.out.println("array : " + Arrays.toString(array));
// 結果
// ↓
//left = a : right = b
//left = ab : right = c
//left = abc : right = d
//array : [a, ab, abc, abcd]
static void parallelSetAll (double[] array, IntToDoubleFunction generator)
型が違うこと以外は、parallelSetAll(int[] array, IntUnaryOperator generator)と使い方は同じです。
API使用例はそちらをご参照ください。
static void parallelSetAll (int[] array, IntUnaryOperator generator)
final var array = new int[5];
System.out.println("before : " + Arrays.toString(array));
Arrays.parallelSetAll(array, index -> {
final var id = Thread.currentThread().getId();
System.out.println("thread id = %d : index = %d".formatted(id, index));
return index * 2;
});
System.out.println("after : " + Arrays.toString(array));
// 結果
// ↓
//before : [0, 0, 0, 0, 0]
//thread id = 16 : index = 2
//thread id = 21 : index = 0
//thread id = 23 : index = 3
//thread id = 20 : index = 4
//thread id = 19 : index = 1
//after : [0, 2, 4, 6, 8]
static void parallelSetAll (long[] array, IntToLongFunction generator)
型が違うこと以外は、parallelSetAll(int[] array, IntUnaryOperator generator)と使い方は同じです。
API使用例はそちらをご参照ください。
static <T> void parallelSetAll (T[] array, IntFunction<? extends T> generator)
final var array = new String[5];
System.out.println("before : " + Arrays.toString(array));
Arrays.parallelSetAll(array, index -> {
final var id = Thread.currentThread().getId();
System.out.println("thread id = %d : index = %d".formatted(id, index));
return "a".repeat(index + 1);
});
System.out.println("after : " + Arrays.toString(array));
// 結果
// ↓
//before : [null, null, null, null, null]
//thread id = 16 : index = 2
//thread id = 20 : index = 4
//thread id = 19 : index = 1
//thread id = 21 : index = 3
//thread id = 22 : index = 0
//after : [a, aa, aaa, aaaa, aaaaa]
static void parallelSort (byte[] a)
型が違うこと以外は、parallelSort(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static void parallelSort (byte[] a, int fromIndex, int toIndex)
型が違うこと以外は、parallelSort(int[] a, int fromIndex, int toIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static void parallelSort (char[] a)
final char[] a = {'d', 'c', 'b', 'a'};
Arrays.parallelSort(a);
System.out.println(Arrays.toString(a)); // [a, b, c, d]
static void parallelSort (char[] a, int fromIndex, int toIndex)
final char[] a = {'d', 'c', 'b', 'a'};
{
final char[] a1 = a.clone();
final char[] a2 = a.clone();
final char[] a3 = a.clone();
final char[] a4 = a.clone();
Arrays.parallelSort(a1, 0, 4);
Arrays.parallelSort(a2, 0, 3);
Arrays.parallelSort(a3, 0, 2);
Arrays.parallelSort(a4, 0, 1);
System.out.println(Arrays.toString(a1)); // [a, b, c, d]
System.out.println(Arrays.toString(a2)); // [b, c, d, a]
System.out.println(Arrays.toString(a3)); // [c, d, b, a]
System.out.println(Arrays.toString(a4)); // [d, c, b, a]
}
{
final char[] a1 = a.clone();
final char[] a2 = a.clone();
final char[] a3 = a.clone();
final char[] a4 = a.clone();
Arrays.parallelSort(a1, 0, 4);
Arrays.parallelSort(a2, 1, 4);
Arrays.parallelSort(a3, 2, 4);
Arrays.parallelSort(a4, 3, 4);
System.out.println(Arrays.toString(a1)); // [a, b, c, d]
System.out.println(Arrays.toString(a2)); // [d, a, b, c]
System.out.println(Arrays.toString(a3)); // [d, c, a, b]
System.out.println(Arrays.toString(a4)); // [d, c, b, a]
}
static void parallelSort (double[] a)
型が違うこと以外は、parallelSort(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static void parallelSort (double[] a, int fromIndex, int toIndex)
型が違うこと以外は、parallelSort(int[] a, int fromIndex, int toIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static void parallelSort (float[] a)
型が違うこと以外は、parallelSort(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static void parallelSort (float[] a, int fromIndex, int toIndex)
型が違うこと以外は、parallelSort(int[] a, int fromIndex, int toIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static void parallelSort (int[] a)
final int[] a = {4, 3, 2, 1};
Arrays.parallelSort(a);
System.out.println(Arrays.toString(a)); // [1, 2, 3, 4]
static void parallelSort (int[] a, int fromIndex, int toIndex)
final int[] a = {4, 3, 2, 1};
{
final int[] a1 = a.clone();
final int[] a2 = a.clone();
final int[] a3 = a.clone();
final int[] a4 = a.clone();
Arrays.parallelSort(a1, 0, 4);
Arrays.parallelSort(a2, 0, 3);
Arrays.parallelSort(a3, 0, 2);
Arrays.parallelSort(a4, 0, 1);
System.out.println(Arrays.toString(a1)); // [1, 2, 3, 4]
System.out.println(Arrays.toString(a2)); // [2, 3, 4, 1]
System.out.println(Arrays.toString(a3)); // [3, 4, 2, 1]
System.out.println(Arrays.toString(a4)); // [4, 3, 2, 1]
}
{
final int[] a1 = a.clone();
final int[] a2 = a.clone();
final int[] a3 = a.clone();
final int[] a4 = a.clone();
Arrays.parallelSort(a1, 0, 4);
Arrays.parallelSort(a2, 1, 4);
Arrays.parallelSort(a3, 2, 4);
Arrays.parallelSort(a4, 3, 4);
System.out.println(Arrays.toString(a1)); // [1, 2, 3, 4]
System.out.println(Arrays.toString(a2)); // [4, 1, 2, 3]
System.out.println(Arrays.toString(a3)); // [4, 3, 1, 2]
System.out.println(Arrays.toString(a4)); // [4, 3, 2, 1]
}
static void parallelSort (long[] a)
型が違うこと以外は、parallelSort(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static void parallelSort (long[] a, int fromIndex, int toIndex)
型が違うこと以外は、parallelSort(int[] a, int fromIndex, int toIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static void parallelSort (short[] a)
型が違うこと以外は、parallelSort(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static void parallelSort (short[] a, int fromIndex, int toIndex)
型が違うこと以外は、parallelSort(int[] a, int fromIndex, int toIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static <T extends Comparable<? super T>> void parallelSort (T[] a)
// StringクラスはComparableを実装しています。
final String[] a = {"d", "c", "b", "a"};
Arrays.parallelSort(a);
System.out.println(Arrays.toString(a)); // [a, b, c, d]
static <T extends Comparable<? super T>> void parallelSort (T[] a, int fromIndex, int toIndex)
// StringクラスはComparableを実装しています。
final String[] a = {"d", "c", "b", "a"};
{
final String[] a1 = a.clone();
final String[] a2 = a.clone();
final String[] a3 = a.clone();
final String[] a4 = a.clone();
Arrays.parallelSort(a1, 0, 4);
Arrays.parallelSort(a2, 0, 3);
Arrays.parallelSort(a3, 0, 2);
Arrays.parallelSort(a4, 0, 1);
System.out.println(Arrays.toString(a1)); // [a, b, c, d]
System.out.println(Arrays.toString(a2)); // [b, c, d, a]
System.out.println(Arrays.toString(a3)); // [c, d, b, a]
System.out.println(Arrays.toString(a4)); // [d, c, b, a]
}
{
final String[] a1 = a.clone();
final String[] a2 = a.clone();
final String[] a3 = a.clone();
final String[] a4 = a.clone();
Arrays.parallelSort(a1, 0, 4);
Arrays.parallelSort(a2, 1, 4);
Arrays.parallelSort(a3, 2, 4);
Arrays.parallelSort(a4, 3, 4);
System.out.println(Arrays.toString(a1)); // [a, b, c, d]
System.out.println(Arrays.toString(a2)); // [d, a, b, c]
System.out.println(Arrays.toString(a3)); // [d, c, a, b]
System.out.println(Arrays.toString(a4)); // [d, c, b, a]
}
static <T> void parallelSort (T[] a, int fromIndex, int toIndex, Comparator<? super T> cmp)
PairとPairComparatorについてはこちらをご参照ください。
final Pair[] a = {
new Pair(2, 2), new Pair(2, 1),
new Pair(1, 2), new Pair(1, 1)};
final var cmp = new PairComparator();
{
final Pair[] a1 = a.clone();
final Pair[] a2 = a.clone();
final Pair[] a3 = a.clone();
final Pair[] a4 = a.clone();
Arrays.parallelSort(a1, 0, 4, cmp);
Arrays.parallelSort(a2, 0, 3, cmp);
Arrays.parallelSort(a3, 0, 2, cmp);
Arrays.parallelSort(a4, 0, 1, cmp);
System.out.println(Arrays.toString(a1)); // [(1, 1), (1, 2), (2, 1), (2, 2)]
System.out.println(Arrays.toString(a2)); // [(1, 2), (2, 1), (2, 2), (1, 1)]
System.out.println(Arrays.toString(a3)); // [(2, 1), (2, 2), (1, 2), (1, 1)]
System.out.println(Arrays.toString(a4)); // [(2, 2), (2, 1), (1, 2), (1, 1)]
}
{
final Pair[] a1 = a.clone();
final Pair[] a2 = a.clone();
final Pair[] a3 = a.clone();
final Pair[] a4 = a.clone();
Arrays.parallelSort(a1, 0, 4, cmp);
Arrays.parallelSort(a2, 1, 4, cmp);
Arrays.parallelSort(a3, 2, 4, cmp);
Arrays.parallelSort(a4, 3, 4, cmp);
System.out.println(Arrays.toString(a1)); // [(1, 1), (1, 2), (2, 1), (2, 2)]
System.out.println(Arrays.toString(a2)); // [(2, 2), (1, 1), (1, 2), (2, 1)]
System.out.println(Arrays.toString(a3)); // [(2, 2), (2, 1), (1, 1), (1, 2)]
System.out.println(Arrays.toString(a4)); // [(2, 2), (2, 1), (1, 2), (1, 1)]
}
static <T> void parallelSort (T[] a, Comparator<? super T> cmp)
PairとPairComparatorについてはこちらをご参照ください。
final Pair[] a = {
new Pair(2, 2), new Pair(2, 1),
new Pair(1, 2), new Pair(1, 1)};
final var cmp = new PairComparator();
Arrays.parallelSort(a, cmp);
System.out.println(Arrays.toString(a)); // [(1, 1), (1, 2), (2, 1), (2, 2)]
static void setAll (double[] array, IntToDoubleFunction generator)
型が違うこと以外は、setAll(int[] array, IntUnaryOperator generator)と使い方は同じです。
API使用例はそちらをご参照ください。
static void setAll (int[] array, IntUnaryOperator generator)
final var array = new int[5];
System.out.println("before : " + Arrays.toString(array));
Arrays.setAll(array, index -> {
System.out.println("index = %d".formatted(index));
return index * 2;
});
System.out.println("after : " + Arrays.toString(array));
// 結果
// ↓
//before : [0, 0, 0, 0, 0]
//index = 0
//index = 1
//index = 2
//index = 3
//index = 4
//after : [0, 2, 4, 6, 8]
static void setAll (long[] array, IntToLongFunction generator)
型が違うこと以外は、setAll(int[] array, IntUnaryOperator generator)と使い方は同じです。
API使用例はそちらをご参照ください。
static <T> void setAll (T[] array, IntFunction<? extends T> generator)
final var array = new String[5];
System.out.println("before : " + Arrays.toString(array));
Arrays.setAll(array, index -> {
System.out.println("index = %d".formatted(index));
return "a".repeat(index + 1);
});
System.out.println("after : " + Arrays.toString(array));
// 結果
// ↓
//before : [null, null, null, null, null]
//index = 0
//index = 1
//index = 2
//index = 3
//index = 4
//after : [a, aa, aaa, aaaa, aaaaa]
static void sort (byte[] a)
型が違うこと以外は、sort(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static void sort (byte[] a, int fromIndex, int toIndex)
型が違うこと以外は、sort(int[] a, int fromIndex, int toIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static void sort (char[] a)
final char[] a = {'d', 'c', 'b', 'a'};
Arrays.sort(a);
System.out.println(Arrays.toString(a)); // [a, b, c, d]
static void sort (char[] a, int fromIndex, int toIndex)
final char[] a = {'d', 'c', 'b', 'a'};
{
final char[] a1 = a.clone();
final char[] a2 = a.clone();
final char[] a3 = a.clone();
final char[] a4 = a.clone();
Arrays.sort(a1, 0, 4);
Arrays.sort(a2, 0, 3);
Arrays.sort(a3, 0, 2);
Arrays.sort(a4, 0, 1);
System.out.println(Arrays.toString(a1)); // [a, b, c, d]
System.out.println(Arrays.toString(a2)); // [b, c, d, a]
System.out.println(Arrays.toString(a3)); // [c, d, b, a]
System.out.println(Arrays.toString(a4)); // [d, c, b, a]
}
{
final char[] a1 = a.clone();
final char[] a2 = a.clone();
final char[] a3 = a.clone();
final char[] a4 = a.clone();
Arrays.sort(a1, 0, 4);
Arrays.sort(a2, 1, 4);
Arrays.sort(a3, 2, 4);
Arrays.sort(a4, 3, 4);
System.out.println(Arrays.toString(a1)); // [a, b, c, d]
System.out.println(Arrays.toString(a2)); // [d, a, b, c]
System.out.println(Arrays.toString(a3)); // [d, c, a, b]
System.out.println(Arrays.toString(a4)); // [d, c, b, a]
}
static void sort (double[] a)
型が違うこと以外は、sort(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static void sort (double[] a, int fromIndex, int toIndex)
型が違うこと以外は、sort(int[] a, int fromIndex, int toIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static void sort (float[] a)
型が違うこと以外は、sort(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static void sort (float[] a, int fromIndex, int toIndex)
型が違うこと以外は、sort(int[] a, int fromIndex, int toIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static void sort (int[] a)
final int[] a = {4, 3, 2, 1};
Arrays.sort(a);
System.out.println(Arrays.toString(a)); // [1, 2, 3, 4]
static void sort (int[] a, int fromIndex, int toIndex)
final int[] a = {4, 3, 2, 1};
{
final int[] a1 = a.clone();
final int[] a2 = a.clone();
final int[] a3 = a.clone();
final int[] a4 = a.clone();
Arrays.sort(a1, 0, 4);
Arrays.sort(a2, 0, 3);
Arrays.sort(a3, 0, 2);
Arrays.sort(a4, 0, 1);
System.out.println(Arrays.toString(a1)); // [1, 2, 3, 4]
System.out.println(Arrays.toString(a2)); // [2, 3, 4, 1]
System.out.println(Arrays.toString(a3)); // [3, 4, 2, 1]
System.out.println(Arrays.toString(a4)); // [4, 3, 2, 1]
}
{
final int[] a1 = a.clone();
final int[] a2 = a.clone();
final int[] a3 = a.clone();
final int[] a4 = a.clone();
Arrays.sort(a1, 0, 4);
Arrays.sort(a2, 1, 4);
Arrays.sort(a3, 2, 4);
Arrays.sort(a4, 3, 4);
System.out.println(Arrays.toString(a1)); // [1, 2, 3, 4]
System.out.println(Arrays.toString(a2)); // [4, 1, 2, 3]
System.out.println(Arrays.toString(a3)); // [4, 3, 1, 2]
System.out.println(Arrays.toString(a4)); // [4, 3, 2, 1]
}
static void sort (long[] a)
型が違うこと以外は、sort(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static void sort (long[] a, int fromIndex, int toIndex)
型が違うこと以外は、sort(int[] a, int fromIndex, int toIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static void sort (short[] a)
型が違うこと以外は、sort(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static void sort (short[] a, int fromIndex, int toIndex)
型が違うこと以外は、sort(int[] a, int fromIndex, int toIndex)と使い方は同じです。
API使用例はそちらをご参照ください。
static void sort (Object[] a)
// StringクラスはComparableを実装しています。
final String[] a = {"d", "c", "b", "a"};
Arrays.sort(a);
System.out.println(Arrays.toString(a)); // [a, b, c, d]
static void sort (Object[] a, int fromIndex, int toIndex)
// StringクラスはComparableを実装しています。
final String[] a = {"d", "c", "b", "a"};
{
final String[] a1 = a.clone();
final String[] a2 = a.clone();
final String[] a3 = a.clone();
final String[] a4 = a.clone();
Arrays.sort(a1, 0, 4);
Arrays.sort(a2, 0, 3);
Arrays.sort(a3, 0, 2);
Arrays.sort(a4, 0, 1);
System.out.println(Arrays.toString(a1)); // [a, b, c, d]
System.out.println(Arrays.toString(a2)); // [b, c, d, a]
System.out.println(Arrays.toString(a3)); // [c, d, b, a]
System.out.println(Arrays.toString(a4)); // [d, c, b, a]
}
{
final String[] a1 = a.clone();
final String[] a2 = a.clone();
final String[] a3 = a.clone();
final String[] a4 = a.clone();
Arrays.sort(a1, 0, 4);
Arrays.sort(a2, 1, 4);
Arrays.sort(a3, 2, 4);
Arrays.sort(a4, 3, 4);
System.out.println(Arrays.toString(a1)); // [a, b, c, d]
System.out.println(Arrays.toString(a2)); // [d, a, b, c]
System.out.println(Arrays.toString(a3)); // [d, c, a, b]
System.out.println(Arrays.toString(a4)); // [d, c, b, a]
}
static <T> void sort (T[] a, int fromIndex, int toIndex, Comparator<? super T> c)
PairとPairComparatorについてはこちらをご参照ください。
final Pair[] a = {
new Pair(2, 2), new Pair(2, 1),
new Pair(1, 2), new Pair(1, 1)};
final var c = new PairComparator();
{
final Pair[] a1 = a.clone();
final Pair[] a2 = a.clone();
final Pair[] a3 = a.clone();
final Pair[] a4 = a.clone();
Arrays.sort(a1, 0, 4, c);
Arrays.sort(a2, 0, 3, c);
Arrays.sort(a3, 0, 2, c);
Arrays.sort(a4, 0, 1, c);
System.out.println(Arrays.toString(a1)); // [(1, 1), (1, 2), (2, 1), (2, 2)]
System.out.println(Arrays.toString(a2)); // [(1, 2), (2, 1), (2, 2), (1, 1)]
System.out.println(Arrays.toString(a3)); // [(2, 1), (2, 2), (1, 2), (1, 1)]
System.out.println(Arrays.toString(a4)); // [(2, 2), (2, 1), (1, 2), (1, 1)]
}
{
final Pair[] a1 = a.clone();
final Pair[] a2 = a.clone();
final Pair[] a3 = a.clone();
final Pair[] a4 = a.clone();
Arrays.sort(a1, 0, 4, c);
Arrays.sort(a2, 1, 4, c);
Arrays.sort(a3, 2, 4, c);
Arrays.sort(a4, 3, 4, c);
System.out.println(Arrays.toString(a1)); // [(1, 1), (1, 2), (2, 1), (2, 2)]
System.out.println(Arrays.toString(a2)); // [(2, 2), (1, 1), (1, 2), (2, 1)]
System.out.println(Arrays.toString(a3)); // [(2, 2), (2, 1), (1, 1), (1, 2)]
System.out.println(Arrays.toString(a4)); // [(2, 2), (2, 1), (1, 2), (1, 1)]
}
static <T> void sort (T[] a, Comparator<? super T> c)
PairとPairComparatorについてはこちらをご参照ください。
final Pair[] a = {
new Pair(2, 2), new Pair(2, 1),
new Pair(1, 2), new Pair(1, 1)};
final var c = new PairComparator();
Arrays.sort(a, c);
System.out.println(Arrays.toString(a)); // [(1, 1), (1, 2), (2, 1), (2, 2)]
static Spliterator.OfDouble spliterator (double[] array)
型が違うこと以外は、spliterator(int[] array)と使い方は同じです。
API使用例はそちらをご参照ください。
static Spliterator.OfDouble spliterator (double[] array, int startInclusive, int endExclusive)
型が違うこと以外は、spliterator(int[] array, int startInclusive, int endExclusive)と使い方は同じです。
API使用例はそちらをご参照ください。
static Spliterator.OfInt spliterator (int[] array)
final int[] array = {1, 2, 3, 4};
final var spliterator = Arrays.spliterator(array);
spliterator.forEachRemaining((IntConsumer) value -> {
System.out.print(value + ",");
});
System.out.println();
// 結果
// ↓
//1,2,3,4,
static Spliterator.OfInt spliterator (int[] array, int startInclusive, int endExclusive)
final int[] array = {1, 2, 3, 4};
Arrays.spliterator(array, 0, 4)
.forEachRemaining((IntConsumer) value -> System.out.print(value + ","));
System.out.println();
Arrays.spliterator(array, 0, 3)
.forEachRemaining((IntConsumer) value -> System.out.print(value + ","));
System.out.println();
Arrays.spliterator(array, 0, 2)
.forEachRemaining((IntConsumer) value -> System.out.print(value + ","));
System.out.println();
Arrays.spliterator(array, 0, 1)
.forEachRemaining((IntConsumer) value -> System.out.print(value + ","));
System.out.println();
// 結果
// ↓
//1,2,3,4,
//1,2,3,
//1,2,
//1,
final int[] array = {1, 2, 3, 4};
Arrays.spliterator(array, 0, 4).
forEachRemaining((IntConsumer) value -> System.out.print(value + ","));
System.out.println();
Arrays.spliterator(array, 1, 4).
forEachRemaining((IntConsumer) value -> System.out.print(value + ","));
System.out.println();
Arrays.spliterator(array, 2, 4).
forEachRemaining((IntConsumer) value -> System.out.print(value + ","));
System.out.println();
Arrays.spliterator(array, 3, 4).
forEachRemaining((IntConsumer) value -> System.out.print(value + ","));
System.out.println();
// 結果
// ↓
//1,2,3,4,
//2,3,4,
//3,4,
//4,
static Spliterator.OfLong spliterator (long[] array)
型が違うこと以外は、spliterator(int[] array)と使い方は同じです。
API使用例はそちらをご参照ください。
static Spliterator.OfLong spliterator (long[] array, int startInclusive, int endExclusive)
型が違うこと以外は、spliterator(int[] array, int startInclusive, int endExclusive)と使い方は同じです。
API使用例はそちらをご参照ください。
static <T> Spliterator<T> spliterator (T[] array)
final String[] array = {"a", "b", "c", "d"};
final var spliterator = Arrays.spliterator(array);
spliterator.forEachRemaining(value -> {
System.out.print(value + ",");
});
System.out.println();
// 結果
// ↓
//a,b,c,d,
static <T> Spliterator<T> spliterator (T[] array, int startInclusive, int endExclusive)
final String[] array = {"a", "b", "c", "d"};
Arrays.spliterator(array, 0, 4).forEachRemaining(value -> System.out.print(value + ","));
System.out.println();
Arrays.spliterator(array, 0, 3).forEachRemaining(value -> System.out.print(value + ","));
System.out.println();
Arrays.spliterator(array, 0, 2).forEachRemaining(value -> System.out.print(value + ","));
System.out.println();
Arrays.spliterator(array, 0, 1).forEachRemaining(value -> System.out.print(value + ","));
System.out.println();
// 結果
// ↓
//a,b,c,d,
//a,b,c,
//a,b,
//a,
final String[] array = {"a", "b", "c", "d"};
Arrays.spliterator(array, 0, 4).forEachRemaining(value -> System.out.print(value + ","));
System.out.println();
Arrays.spliterator(array, 1, 4).forEachRemaining(value -> System.out.print(value + ","));
System.out.println();
Arrays.spliterator(array, 2, 4).forEachRemaining(value -> System.out.print(value + ","));
System.out.println();
Arrays.spliterator(array, 3, 4).forEachRemaining(value -> System.out.print(value + ","));
System.out.println();
// 結果
// ↓
//a,b,c,d,
//b,c,d,
//c,d,
//d,
static DoubleStream stream (double[] array)
型が違うこと以外は、stream(int[] array)と使い方は同じです。
API使用例はそちらをご参照ください。
static DoubleStream stream (double[] array, int startInclusive, int endExclusive)
型が違うこと以外は、stream(int[] array, int startInclusive, int endExclusive)と使い方は同じです。
API使用例はそちらをご参照ください。
static IntStream stream (int[] array)
final int[] array = {1, 2, 3, 4};
final var stream = Arrays.stream(array);
final var s = stream.mapToObj(value -> String.valueOf(value * 2)).collect(Collectors.joining(", "));
System.out.println(s); // 2, 4, 6, 8
static IntStream stream (int[] array, int startInclusive, int endExclusive)
final int[] array = {1, 2, 3, 4};
final var s1 = Arrays.stream(array, 0, 4)
.mapToObj(value -> String.valueOf(value * 2)).collect(Collectors.joining(", "));
final var s2 = Arrays.stream(array, 0, 3)
.mapToObj(value -> String.valueOf(value * 2)).collect(Collectors.joining(", "));
final var s3 = Arrays.stream(array, 0, 2)
.mapToObj(value -> String.valueOf(value * 2)).collect(Collectors.joining(", "));
final var s4 = Arrays.stream(array, 0, 1)
.mapToObj(value -> String.valueOf(value * 2)).collect(Collectors.joining(", "));
System.out.println(s1); // 2, 4, 6, 8
System.out.println(s2); // 2, 4, 6
System.out.println(s3); // 2, 4
System.out.println(s4); // 2
final int[] array = {1, 2, 3, 4};
final var s1 = Arrays.stream(array, 0, 4)
.mapToObj(value -> String.valueOf(value * 2)).collect(Collectors.joining(", "));
final var s2 = Arrays.stream(array, 1, 4)
.mapToObj(value -> String.valueOf(value * 2)).collect(Collectors.joining(", "));
final var s3 = Arrays.stream(array, 2, 4)
.mapToObj(value -> String.valueOf(value * 2)).collect(Collectors.joining(", "));
final var s4 = Arrays.stream(array, 3, 4)
.mapToObj(value -> String.valueOf(value * 2)).collect(Collectors.joining(", "));
System.out.println(s1); // 2, 4, 6, 8
System.out.println(s2); // 4, 6, 8
System.out.println(s3); // 6, 8
System.out.println(s4); // 8
static LongStream stream (long[] array)
型が違うこと以外は、stream(int[] array)と使い方は同じです。
API使用例はそちらをご参照ください。
static LongStream stream (long[] array, int startInclusive, int endExclusive)
型が違うこと以外は、stream(int[] array, int startInclusive, int endExclusive)と使い方は同じです。
API使用例はそちらをご参照ください。
static <T> Stream<T> stream (T[] array)
final String[] array = {"a", "b", "c", "d"};
final var stream = Arrays.stream(array);
final var s = stream.map(value -> value.repeat(3)).collect(Collectors.joining(", "));
System.out.println(s); // aaa, bbb, ccc, ddd
static <T> Stream<T> stream (T[] array, int startInclusive, int endExclusive)
final String[] array = {"a", "b", "c", "d"};
final var s1 = Arrays.stream(array, 0, 4)
.map(value -> value.repeat(3)).collect(Collectors.joining(", "));
final var s2 = Arrays.stream(array, 0, 3)
.map(value -> value.repeat(3)).collect(Collectors.joining(", "));
final var s3 = Arrays.stream(array, 0, 2)
.map(value -> value.repeat(3)).collect(Collectors.joining(", "));
final var s4 = Arrays.stream(array, 0, 1)
.map(value -> value.repeat(3)).collect(Collectors.joining(", "));
System.out.println(s1); // aaa, bbb, ccc, ddd
System.out.println(s2); // aaa, bbb, ccc
System.out.println(s3); // aaa, bbb
System.out.println(s4); // aaa
final String[] array = {"a", "b", "c", "d"};
final var s1 = Arrays.stream(array, 0, 4)
.map(value -> value.repeat(3)).collect(Collectors.joining(", "));
final var s2 = Arrays.stream(array, 1, 4)
.map(value -> value.repeat(3)).collect(Collectors.joining(", "));
final var s3 = Arrays.stream(array, 2, 4)
.map(value -> value.repeat(3)).collect(Collectors.joining(", "));
final var s4 = Arrays.stream(array, 3, 4)
.map(value -> value.repeat(3)).collect(Collectors.joining(", "));
System.out.println(s1); // aaa, bbb, ccc, ddd
System.out.println(s2); // bbb, ccc, ddd
System.out.println(s3); // ccc, ddd
System.out.println(s4); // ddd
static String toString (boolean[] a)
final boolean[] a = {true, false, true, false};
System.out.println(Arrays.toString(a)); // [true, false, true, false]
static String toString (byte[] a)
型が違うこと以外は、toString(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static String toString (char[] a)
final char[] a = {'a', 'b', 'c', 'd'};
System.out.println(Arrays.toString(a)); // [a, b, c, d]
static String toString (double[] a)
型が違うこと以外は、toString(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static String toString (float[] a)
型が違うこと以外は、toString(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static String toString (int[] a)
final int[] a = {1, 2, 3, 4};
System.out.println(Arrays.toString(a)); // [1, 2, 3, 4]
static String toString (long[] a)
型が違うこと以外は、toString(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static String toString (short[] a)
型が違うこと以外は、toString(int[] a)と使い方は同じです。
API使用例はそちらをご参照ください。
static String toString (Object[] a)
final String[] a = {"a", "b", "c", "d"};
System.out.println(Arrays.toString(a)); // [a, b, c, d]
関連記事
- API 使用例