首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

new String(byte[] bytes, int offset,int length)有关问题

2012-06-03 
newString(byte[] bytes, int offset,int length)问题为什么不是输出:100110021003Java codepublic class

new String(byte[] bytes, int offset,int length)问题
为什么不是输出:
1001
1002
1003

Java code
public class dsf {    /**     * @param args     */    public static void main(String[] args) {        String re,restr="";        int tr=0,i;        String str="1001-1002-1003-1004-1005";        byte[] buf= str.getBytes();        for(i=0;i<buf.length;i++)        {            if(buf[i]=='-')            {                re=new String(buf,tr,i);                System.out.println(re+" "+tr+" "+i);                tr=i+1;            }        }    }}


[解决办法]
bytes - 要解码为字符的字节
offset - 要解码的首字节的索引
length - 要解码的字节数

热点排行