[英]Sort Array by Alphabetical order using SelectionSort without Array.sort
[英]Sort byte array using Array.sort()
真的很愚蠢的問題,但我有點卡在這一個:
byte[] bytes = new byte[]{1, 2, 3};
Arrays.sort(bytes, (byte a, byte b) -> 0);
為什么lambda不匹配Array.sort
任何方法,我該如何解決?
我猜你正在嘗試使用Arrays.sort(T[] a, Comparator<? super T> c)
,所以問題是byte
不是T
,因為它是一個原始類型。 我想這可以與Byte
使用。
沒有sort
方法接受原始值數組和 Comparator
。 遺憾的是,只能使用比較器對對象數組進行排序。
嘗試
Byte[] bytes = new Byte[] { 1, 2, 3 };
Arrays.sort(bytes, (Byte a, Byte b) -> 0);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.