Mr_WuW 2019-09-03 17:01 采纳率: 0%
浏览 2333

java中多个byte[]组合成一个有什么好办法

需要将多个不通长度的byte[]按顺序合并成一个,请问有什么效率较高的好办法?

  • 写回答

1条回答 默认 最新

  • Json-Huang 2019-09-03 20:08
    关注

    可以循环遍历byte[]通过System.arraycopy实现,如:

    private static byte[] byteMerger(byte[]... byteList) {
        int lengthByte = 0;
            for (int i = 0; i < byteList.length; i++) {
                lengthByte += byteList[i].length;
            }
            byte[] allByte = new byte[lengthByte];
            int countLength = 0;
            for (int i = 0; i < byteList.length; i++) {
                byte[] b = byteList[i];
                System.arraycopy(b, 0, allByte, countLength, b.length);
                countLength += b.length;
            }
            return allByte;
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序