java里面String字符串和其他类型转换

来源:互联网 发布:gps测量数据怎么处理 编辑:程序博客网 时间:2024/06/12 19:04

本文地址:

1 byte数组和String字符串

1-1 string 转 byte[]

String str = "Hello";byte[] srtbyte = str.getBytes();

1-2 byte[] 转 string

byte[] srtbyte;String res = new String(srtbyte);System.out.println(res);

1-3 设定编码方式相互转换

String str = "hello";byte[] srtbyte = null;try {    srtbyte = str.getBytes("UTF-8");    String res = new String(srtbyte,"UTF-8");    System.out.println(res);} catch (UnsupportedEncodingException e) {    // TODO Auto-generated catch block    e.printStackTrace();}
0 0
原创粉丝点击