String中new String(byte[] b, int n, int m)的理解

来源:互联网 发布:java圆类返回值 编辑:程序博客网 时间:2024/05/18 05:26
String item = new String(b, n, m)的用法,其中b为byte[]数组,n,m为int类型.
简单的来说就是byte数组b从下标为n开始前进m个下标的那一段数组变为字符串item。概念比较难理解,下面直接看例子吧!
例如1:   
          b={'1' ,'2', '3', '4', '5', '6', '7', '8'};
          String item=new String(b,2,2)
          结果 item=34
例如2: 
          String item=new String(b,0,3)
          结果 item=123

看例子可以很清楚的看到new String(byte[] b, int n, int m)中个参数的作用。这种情况一般出现在要对byte进行处理的情况。
例如Android中加密和解密的过程就会用到这种情况。
1 0
原创粉丝点击