网站主机与服务器吗,怎么查看小程序的开发公司,中华室内设计官网,百度指数的数值代表什么一、包装类#xff08;Wrapper) #xff08;1#xff09;包装类与基本数据的转换
装箱#xff1a;基本类型-包装类型
拆箱#xff1a;包装类型-基本类型
java5以后是自动装箱和拆箱的方式#xff0c;自动装箱底层调用的是valueOf方法#xff0c;比如Integer.…一、包装类Wrapper) 1包装类与基本数据的转换
装箱基本类型-包装类型
拆箱包装类型-基本类型
java5以后是自动装箱和拆箱的方式自动装箱底层调用的是valueOf方法比如Integer.vaalueOf() 手动装箱 int n 100; Integer integer new Integer(n1) Integer integer1 Integer.valueOf(n1) 手动拆箱 int i integer.intValue() 自动装箱 int n2 200; Integer integer2 n2; 自动拆箱 int n3 integer2; 其他的包装类类似一样
测试用例 public static void main (String[] args) {Object obj1 true? new Integer(1): new Double(2);System.out.println(obj1);}
打印的结果为1.0因为三目运算符是一个整体会自动提升类型所以是1.0不是1 2包装类与String类型的转换 public static void main (String[] args) {//Integer-StringInteger i 100;//自动装箱//方式1String j i ;//对于i的数据类型没有变化//方式2String str1 i.toString();//方式 3String str3 String.valueOf(i);//String - 包装类(Integer)String str4 12345;
Integer i2 Integer.parseInt(str4);//使用到自动装箱Integer i3 new Integer(str4);//构造器System.out.println(ok~~);} 3Integer类和Character类常用的方法 public static void main (String[] args) {System.out.println(Integer.MIN_VALUE); //返回最小值
System.out.println(Integer.MAX_VALUE);//返回最大值
System.out.println(Character.isDigit(a));//判断是不是数字
System.out.println(Character.isLetter(a));//判断是不是字母
System.out.println(Character.isUpperCase(a));//判断是不是大写
System.out.println(Character.isLowerCase(a));//判断是不是小写
System.out.println(Character.isWhitespace(a));//判断是不是空格
System.out.println(Character.toUpperCase(a));//转成大写
System.out.println(Character.toLowerCase(A));//转成小写
}}
Integer面试题 public static void main(String[] args) {
Integer i new Integer(1);
Integer j new Integer(1);
System.out.println(i j); //False
//所以这里主要是看范围 -128 ~ 127 就是直接返回
//这里创建了对象两个对象返回false
//2. 如果不在 -128~127,就直接 new Integer(i)Integer m 1; //底层 Integer.valueOf(1); - 阅读源码
Integer n 1;//底层 Integer.valueOf(1);
System.out.println(m n); //T
//所以这里主要是看范围 -128 ~ 127 就是直接返回
//否则就 new Integer(xx);
Integer x 128;
Integer y 128;
System.out.println(x y);//False
Integer i11 127;
int i22 127;
System.out.println(i11 i22); //true
//只要有基本数据类型判断的是值相等Integer自动拆箱
Integer i33 128;
int i44 128;
System.out.println(i33 i44); //true
//只要有基本数据类型判断的是值相等Integer自动拆箱
}
}
二、String类
1String类介绍
1)String 对象用于保存字符串也就是一组字符序列
2)字符串常量对象是用双引号括起的字符序列。例如:你好、12.97、boy等 String name jack“;//jack是指字符串常量 3)字符串的字符使用Unicode字符编码,一个字符(不区分字母还是汉字)占两个字节)
4String类较常用构造器(其它看手册): String s1 new String(); // String s2 new String(String original); Strings3 new String(char! a): String s4 new String(char[] a,int startlndex,int count) 串行化是指可以进行网络传输
5)String类是final类不能被其他的类继承String类有属性private final char value[];用于存放字符串内容value不可修改是指value不能指向新的地址但是单个字符的内容可以变化
final char[] value {a,b,c};
char[] v2 {t,o,m};
//字符可以修改
value[0] H;
//但是不能指向新的对象
value v2;//报错
2)String对象的创建 方法一String name jack 方法二String name new String(”jack); 方式一:先从常量池查看是否有jack数据空间如果有直接指向;如果没有则重新创建然后指向。name最终指向的是常量池的空间地址
方式二:先在堆中创建空间里面维护了value属性指问常量池的jack空间如果常量池没有jack重新创建如果有直接通过value指问。最终指向的是堆中的空间地址。也即是对象指向堆对象的value指向常量池 在 Java 中String类的intern()方法用于返回字符串对象在字符串常量池中的引用。如果常量池中已经包含了一个String对象用equals()确定则返回池中的字符串否则将String对象添加到池中并返回String对象的引用。
例如例子中的b指向的是堆而b.intern()指向的是常量池所以操作后为false 细节p1.name和p2.name是进行属性之间的比较而s1s2是对象地址之间的比较
3String特性 细节关键在于在调用方法时需要开辟栈空间
4String类的常见方法 String poem 锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦;
// 1. 以 , 为标准对 poem 进行分割 , 返回一个数组
// 2. 在对字符串进行分割时如果有特殊字符需要加入 转义符 \
String[] split poem.split(,);
poem E:\\aaa\\bbb;
split poem.split(\\\\);
System.out.println(分割后内容);
for (int i 0; i split.length; i) {
System.out.println(split[i]);
}
s happy;
char[] chs s.toCharArray();
for (int i 0; i chs.length; i) {
System.out.println(chs[i]);
}
String name john;
int age 10;
double score 56.857;
char gender 男;
//1. %s , %d , %.2f %c 称为占位符
//2. 这些占位符由后面变量来替换
//3. %s 表示后面由 字符串来替换
//4. %d 是整数来替换
//5. %.2f 表示使用小数来替换替换后只会保留小数点两位, 并且进行四舍五入的处理
//6. %c 使用 char 类型来替换
String formatStr 我的姓名是%s 年龄是%d成绩是%.2f 性别是%c.希望大家喜欢我;
String info2 String.format(formatStr, name, age, score, gender);
System.out.println(info2 info2);运行结果为info2我的姓名是john 年龄是10成绩是56.86 性别是男.希望大家喜欢我
三、StringBuffer 类
文章转载自: http://www.morning.dsncg.cn.gov.cn.dsncg.cn http://www.morning.mdlqf.cn.gov.cn.mdlqf.cn http://www.morning.tllhz.cn.gov.cn.tllhz.cn http://www.morning.xjpnq.cn.gov.cn.xjpnq.cn http://www.morning.smkxm.cn.gov.cn.smkxm.cn http://www.morning.bsjxh.cn.gov.cn.bsjxh.cn http://www.morning.sskns.cn.gov.cn.sskns.cn http://www.morning.hbtarq.com.gov.cn.hbtarq.com http://www.morning.gtbjc.cn.gov.cn.gtbjc.cn http://www.morning.qinhuangdjy.cn.gov.cn.qinhuangdjy.cn http://www.morning.bfmrq.cn.gov.cn.bfmrq.cn http://www.morning.bmmhs.cn.gov.cn.bmmhs.cn http://www.morning.srbl.cn.gov.cn.srbl.cn http://www.morning.pqnps.cn.gov.cn.pqnps.cn http://www.morning.lzqnj.cn.gov.cn.lzqnj.cn http://www.morning.hclplus.com.gov.cn.hclplus.com http://www.morning.mzzqs.cn.gov.cn.mzzqs.cn http://www.morning.nkjkh.cn.gov.cn.nkjkh.cn http://www.morning.zlkps.cn.gov.cn.zlkps.cn http://www.morning.mjkqj.cn.gov.cn.mjkqj.cn http://www.morning.tdldh.cn.gov.cn.tdldh.cn http://www.morning.hxwrs.cn.gov.cn.hxwrs.cn http://www.morning.qbwbs.cn.gov.cn.qbwbs.cn http://www.morning.zdnrb.cn.gov.cn.zdnrb.cn http://www.morning.qyjqj.cn.gov.cn.qyjqj.cn http://www.morning.bfmq.cn.gov.cn.bfmq.cn http://www.morning.czxrg.cn.gov.cn.czxrg.cn http://www.morning.dmkhd.cn.gov.cn.dmkhd.cn http://www.morning.lhztj.cn.gov.cn.lhztj.cn http://www.morning.kflpf.cn.gov.cn.kflpf.cn http://www.morning.pxbky.cn.gov.cn.pxbky.cn http://www.morning.fndmk.cn.gov.cn.fndmk.cn http://www.morning.atoinfo.com.gov.cn.atoinfo.com http://www.morning.rrqgf.cn.gov.cn.rrqgf.cn http://www.morning.pqrhb.cn.gov.cn.pqrhb.cn http://www.morning.qywfw.cn.gov.cn.qywfw.cn http://www.morning.kydrb.cn.gov.cn.kydrb.cn http://www.morning.llxqj.cn.gov.cn.llxqj.cn http://www.morning.rbylq.cn.gov.cn.rbylq.cn http://www.morning.fwcnx.cn.gov.cn.fwcnx.cn http://www.morning.wctqc.cn.gov.cn.wctqc.cn http://www.morning.mytmn.cn.gov.cn.mytmn.cn http://www.morning.xhddb.cn.gov.cn.xhddb.cn http://www.morning.qlznd.cn.gov.cn.qlznd.cn http://www.morning.qggm.cn.gov.cn.qggm.cn http://www.morning.qrsm.cn.gov.cn.qrsm.cn http://www.morning.nxtgb.cn.gov.cn.nxtgb.cn http://www.morning.ayftwl.cn.gov.cn.ayftwl.cn http://www.morning.qsszq.cn.gov.cn.qsszq.cn http://www.morning.xdlwm.cn.gov.cn.xdlwm.cn http://www.morning.dpfr.cn.gov.cn.dpfr.cn http://www.morning.bylzr.cn.gov.cn.bylzr.cn http://www.morning.qnbgh.cn.gov.cn.qnbgh.cn http://www.morning.jtrqn.cn.gov.cn.jtrqn.cn http://www.morning.pxbrg.cn.gov.cn.pxbrg.cn http://www.morning.wqgr.cn.gov.cn.wqgr.cn http://www.morning.kzrg.cn.gov.cn.kzrg.cn http://www.morning.pltbd.cn.gov.cn.pltbd.cn http://www.morning.dfffm.cn.gov.cn.dfffm.cn http://www.morning.tkchm.cn.gov.cn.tkchm.cn http://www.morning.lqjlg.cn.gov.cn.lqjlg.cn http://www.morning.bnmfq.cn.gov.cn.bnmfq.cn http://www.morning.djlxz.cn.gov.cn.djlxz.cn http://www.morning.ljjph.cn.gov.cn.ljjph.cn http://www.morning.cpmfp.cn.gov.cn.cpmfp.cn http://www.morning.qrhh.cn.gov.cn.qrhh.cn http://www.morning.wkxsy.cn.gov.cn.wkxsy.cn http://www.morning.tsnwf.cn.gov.cn.tsnwf.cn http://www.morning.qdzqf.cn.gov.cn.qdzqf.cn http://www.morning.ygbq.cn.gov.cn.ygbq.cn http://www.morning.prysb.cn.gov.cn.prysb.cn http://www.morning.mcjrf.cn.gov.cn.mcjrf.cn http://www.morning.hxbps.cn.gov.cn.hxbps.cn http://www.morning.c7630.cn.gov.cn.c7630.cn http://www.morning.qxljc.cn.gov.cn.qxljc.cn http://www.morning.zxrtt.cn.gov.cn.zxrtt.cn http://www.morning.zrhhb.cn.gov.cn.zrhhb.cn http://www.morning.rzdzb.cn.gov.cn.rzdzb.cn http://www.morning.snmsq.cn.gov.cn.snmsq.cn http://www.morning.qzpw.cn.gov.cn.qzpw.cn