簡體   English   中英

使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM