首页 > 其他 > 详细

整理类型转换

时间:2020-07-13 22:14:41      阅读:54      评论:0      收藏:0      [点我收藏+]


字符串和字节数组
String str = "罗长";

byte[] sb = str.getBytes();//字符串转字节数组
byte[] b={(byte)0xB8,(byte)0xDF,(byte)0xCB,(byte)0xD9};

String str= new String (b);//字节数组转字符串

字符串和字符数组
string str = "mytest";  
 char[] chars = str.ToCharArray(); //字符串转字符数组

char[] chs = new char[]{’a’,’b’,’c’,’d’,’e’};

 String s4 = new String(chs); //字符数组转字符串

字符串和基本数据类型
int i=Integer.parseInt("123");//字符串转基本数据类型

//基本数据类型转字符串的三种方法

“sum”=1+1;//1.双引号:“”+基本数据类型

String i=String.valueOf(122);//2.调用String类中的valueof方法

String i=Double.toString(12.1);//3.调用包装类中独有的tostring方法



基本数据类型和包装对象
Integer i=new Integer(111);//基本数据类型转包装类型对象

Integer i=Integer.valueOf(111);//封装成包装类型

int num=i.intValue();//包装类转基本数据类型

 

整理类型转换

原文:https://www.cnblogs.com/111wdh/p/13292407.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!