因工作的需要,在从事 .Net 的开发中接触到了 Java, 虽然在大学的时候学过一段Java 编程,但并没有在实际的工作中使用过, Java 和 .Net的C#语法很相似,都是面向对象的,感觉在语法上只有些细微的差异,这里主要介绍以下,将两个数组合并成的操作,废话不多说,直接上代码:

    //System.arraycopy()方法
public static byte[] byteMerger(byte[] bt1, byte[] bt2){
byte[] bt3 = new byte[bt1.length+bt2.length];
System.arraycopy(bt1, , bt3, , bt1.length);
System.arraycopy(bt2, , bt3, bt1.length, bt2.length);
return bt3;
}
    // 使用两个 for 语句
//java 合并两个byte数组
public static byte[] byteMerger(byte[] bt1, byte[] bt2){
byte[] bt3 = new byte[bt1.length+bt2.length];
int i=0;
for(byte bt: bt1){
bt3[i]=bt;
i++;
} for(byte bt: bt2){
bt3[i]=bt;
i++;
}
return bt3;
}
    // 使用ArrayList方法
//java 合并两个byte数组
public static byte[] byteMerger(byte[] bt1, byte[] bt2){
List result = new ArrayList();
result.addAll(bt1);
result.addAll(bt2);
return result.toArray();
}
// 使用 Arrays.copyOf() 方法,但要在 java6++版本中
public static String[] concat(String[] first, String[] second) {
String[] result = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(second, 0, result, first.length, second.length);
return result;
}

// 使用ArrayUtils.addAll(Object[], Object[])方法,在包apache-commons中
public static String[] concat(String[] first, String[] second) {
String[] both = (String[]) ArrayUtils.addAll(first, second);
return result;
}

java 中byte[] 数组的合并的更多相关文章

  1. 【转】java中byte数组与int类型的转换(两种方式)----不错

    原文网址:http://blog.csdn.net/piaojun_pj/article/details/5903009 java中byte数组与int类型的转换,在网络编程中这个算法是最基本的算法, ...

  2. [转载] java中byte数组与int,long,short间的转换

    文章转载自http://blog.csdn.net/leetcworks/article/details/7390731 package com.util; /** * * <ul> * ...

  3. java中byte数组与int,long,short间的转换

    http://blog.csdn.net/leetcworks/article/details/7390731 package com.util; /** * * <ul> * <l ...

  4. java中byte数组,二进制binary安装chunk大小读取数据

    int CHUNKED_SIZE = 8000; public void recognizeText(byte[] data) throws InterruptedException, IOExcep ...

  5. java中byte数组与int类型的转换(两种方式)

    http://blog.csdn.net/z69183787/article/details/38564219 http://blog.csdn.net/z69183787/article/detai ...

  6. Java 中 byte、byte 数组和 int、long 之间的转换

    Java 中 byte 和 int 之间的转换源码: //byte 与 int 的相互转换 public static byte intToByte(int x) { return (byte) x; ...

  7. .NET和JAVA中BYTE的区别以及JAVA中“DES/CBC/PKCS5PADDING” 加密解密在.NET中的实现

    场景:java 作为客户端调用已有的一个.net写的server的webservice,输入string,返回字节数组. 问题:返回的值不是自己想要的,跟.net客户端直接调用总是有差距 分析:平台不 ...

  8. Java中byte与16进制字符串的互相转换

    * Convert byte[] to hex string.这里我们可以将byte转换成int,然后利用Integer.toHexString(int)来转换成16进制字符串. * @param s ...

  9. 慕课网-安卓工程师初养成-6-3 如何使用 Java 中的数组

    来源:http://www.imooc.com/code/1525 Java 中操作数组只需要四个步骤: 1. 声明数组 语法:  或者  其中,数组名可以是任意合法的变量名,如: 2. 分配空间 简 ...

随机推荐

  1. Python try/except异常处理机制

    1. use try, except, finally try: data=open('its.txt','w') print('its..', file=data) except: print('f ...

  2. makefile 分析 -- 内置变量及自动变量

    makefile 分析1  -p 选项,可以打印出make过程中的数据库, 下面研究一下内置的变量和规则. -n 选项, 只运行,不执行, -d 选项,相当于--debug=a,  b(basic), ...

  3. android关于AndroidManifest.xml详细分析

    http://my.eoe.cn/1087692/archive/5927.html 一.关于AndroidManifest.xmlAndroidManifest.xml 是每个android程序中必 ...

  4. 黄聪:WordPress 函数:add_filter()(添加过滤器)

    add_filter() 可以挂载一个函数到指定的过滤器上. 用法 add_filter( $tag, $function_to_add, $priority, $accepted_args ); 参 ...

  5. 黄聪:360浏览器如何使用插件实现解除网页禁用右键复制的限制(Enable Copy)

    使用Enable Copy插件即可. 插件下载:Enable-Copy_v1.15.rar

  6. System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list

    static void Main(string[] args) { StringBuilder sb = new StringBuilder(); string test = "124454 ...

  7. CF 501C Misha and Forest 好题

    C. Misha and Forest   Let's define a forest as a non-directed acyclic graph (also without loops and ...

  8. poj 2567 Code the Tree 河南第七届省赛

    Code the Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2350   Accepted: 906 Desc ...

  9. 查看iis错误日志时提示找不到 freb.xsl的解决方法

    http://stackoverflow.com/questions/786638/how-can-i-get-gzip-compression-in-iis7-working/787251 Look ...

  10. ruby4种比较符号

    The == comparison checks whether two values are equal eql? checks if two values are equal and of the ...