2
真是愚蠢的問題,但我被困在這一個位:排序字節數組
byte[] bytes = new byte[]{1, 2, 3};
Arrays.sort(bytes, (byte a, byte b) -> 0);
爲什麼不是拉姆達匹配Array.sort
任何方法和如何解決它?
真是愚蠢的問題,但我被困在這一個位:排序字節數組
byte[] bytes = new byte[]{1, 2, 3};
Arrays.sort(bytes, (byte a, byte b) -> 0);
爲什麼不是拉姆達匹配Array.sort
任何方法和如何解決它?
有沒有sort
方法接受原始值的數組和 a Comparator
。不幸的是,只有對象數組可以用比較器排序。
嘗試
Byte[] bytes = new Byte[] { 1, 2, 3 };
Arrays.sort(bytes, (Byte a, Byte b) -> 0);
我想你試圖使用Arrays.sort(T[] a, Comparator<? super T> c)
,所以問題是byte
不是T
,因爲它是一種原始類型。我想這可以用Byte
代替。