当前位置: 首页 > news >正文

一个网站需要怎么做海口网站建设咨询

一个网站需要怎么做,海口网站建设咨询,优秀网站首页,湖南省建设厅电话号码是多少目录 八大Wrapper类包装类的分类 装箱和拆箱包装类和基本数据类型之间的转换常见面试题 包装类方法包装类型和String类型的相互转换包装类常用方法#xff08;以Integer类和Character类为例#xff09;Integer类和Character类的常用方法 Integer创建机制#xff08;面试题以Integer类和Character类为例Integer类和Character类的常用方法 Integer创建机制面试题面试题1面试题2 八大Wrapper类 包装类的分类 1.针对8种基本数据类型相应的引用类型—包装类 2.有了类的特点就可以调用类的方法。 相关类图如下 示例代码 package com.hspedu.wrapper;/*** author 韩顺平* version 1.0*/ public class WrapperType {public static void main(String[] args) {//boolean - Boolean//char - Character//byte - Byte//int - Integer//long - long//float - Float//double - Double//short - Short} } 装箱和拆箱 包装类和基本数据类型之间的转换 1.jdk5 前需手动装箱和拆箱。装箱基本类型 - 包装类型反之为拆箱 2.jdk5 以后含jdk5采用自动装箱和拆箱的方式【即jdk会在底层自动的帮我们调用相应方法进行转换】 3.自动装箱底层调用的是valueOf方法如Integer.valueOf() 示例代码 package com.hspedu.wrapper;/*** author 韩顺平* version 1.0*/ public class Integer01 {public static void main(String[] args) {//演示int -- Integer 的装箱和拆箱//jdk5前是手动装箱和拆箱//手动装箱 int-Integerint n1 100;Integer integer new Integer(n1);Integer integer1 Integer.valueOf(n1);//手动拆箱//Integer - intint i integer.intValue();//jdk5后就可以自动装箱和自动拆箱int n2 200;//自动装箱 int-IntegerInteger integer2 n2; //底层使用的是 Integer.valueOf(n2)//自动拆箱 Integer-intint n3 integer2; //底层仍然使用的是 intValue()方法} } 其它包装类的用法类似 常见面试题 示例代码 package com.hspedu.wrapper;/*** author 韩顺平* version 1.0*/ public class WrapperExercise01 {public static void main(String[] args) {Double d 100d; //ok, 自动装箱 Double.valueOf(100d);Float f 1.5f; //ok, 自动装箱 Float.valueOf(1.5f);Object obj1 true? new Integer(1) : new Double(2.0);//三元运算符【是一个整体】 一真大师System.out.println(obj1);// 什么? 1.0Object obj2;if(true)obj2 new Integer(1);elseobj2 new Double(2.0);System.out.println(obj2);//1//输出什么 ? 1 分别计算} } 解析 ① 第一题中由于应该将三元运算符看做一个整体故会以三元运算符中精度最高的那个类型作为基准来提升其他值的精度 ② 而第二题中的 if 和 else 是两条独立的语句故精度不会互相影响 包装类方法 包装类型和String类型的相互转换 示例代码代码中以Integer为例其余包装类用法类似 package com.hspedu.wrapper;/*** author 韩顺平* version 1.0*/ public class WrapperVSString {public static void main(String[] args) {//包装类(Integer)-StringInteger i 100;//自动装箱//方式1String str1 i ;//方式2String str2 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~~);} } 这里介绍的是包装类与String类之间的相互转换。实际我们可以将这里介绍的方法中的所有包装类的位置替换成基本数据类型因为底层会自动进行拆装箱 包装类常用方法以Integer类和Character类为例 Integer类和Character类的常用方法 示例代码 package com.hspedu.wrapper;/*** author 韩顺平* version 1.0*/ public class WrapperMethod {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创建机制面试题 面试题1 代码及解析 package com.hspedu.wrapper;/*** author 韩顺平* version 1.0*/ public class WrapperExercise02 {public static void main(String[] args) {Integer i new Integer(1);Integer j new Integer(1);System.out.println(i j); //False//所以这里主要是看范围 -128 ~ 127 就是直接返回/*老韩解读//1. 如果i 在 IntegerCache.low(-128)~IntegerCache.high(127),就直接从数组返回//2. 如果不在 -128~127,就直接 new Integer(i)源码如下public static Integer valueOf(int i) {if (i IntegerCache.low i IntegerCache.high)return IntegerCache.cache[i (-IntegerCache.low)];return new Integer(i);}*/// 这里1是在-128~127之间。故是从缓存数组中返回而缓存数组又已经在类加载时就创建好了是不可变的所以返回的是同一个对象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.valueOf(1);Integer y 128;//底层Integer.valueOf(1);System.out.println(x y);//False} } Integer.valueOf()中IntegerCache为Integer类的静态内部类而其中的Integer cache[]数组为static final静态常量而缓存数组是在类加载时就已经事先创建好了 面试题2 代码及解析 package com.hspedu.wrapper;/*** author 韩顺平* version 1.0*/ public class WrapperExercise03 {public static void main(String[] args) {//示例一Integer i1 new Integer(127);Integer i2 new Integer(127);System.out.println(i1 i2);//F //示例二Integer i3 new Integer(128);Integer i4 new Integer(128);System.out.println(i3 i4);//F//示例三Integer i5 127;//底层Integer.valueOf(127)Integer i6 127;//-128~127System.out.println(i5 i6); //T //示例四Integer i7 128;Integer i8 128;System.out.println(i7 i8);//F //示例五Integer i9 127; //Integer.valueOf(127)Integer i10 new Integer(127);System.out.println(i9 i10);//F//示例六Integer i11127;int i12127; //只有有基本数据类型判断的是 //值是否相同System.out.println(i11i12); //T //示例七Integer i13128;int i14128;System.out.println(i13i14);//T} } 注意当使用运算符时若存在基本数据类型则判断的是值是否相同
http://www.dnsts.com.cn/news/261267.html

相关文章:

  • 福州网站建设询q479185700上快炉石吐司做的网站
  • 一般用什么做网站首页网站建设的栏目策划
  • 海外 网站 推广wordpress安装卡住了
  • 松江网站建设推广Https全局wordpress
  • 建设网站会员湖北省城乡建设厅网站首页
  • 韩国网站设计欣赏做网站优化的好处
  • 上海网站备案人工服务器360平台怎么做网站优化
  • 长沙网站建设好处银行营销活动方案
  • 北京网站页面设计网站制作电话多少
  • 阿里巴巴怎么做不花钱的网站网站开发上证k线
  • 海西州公司网站建设百度免费下载
  • 怎么查网站域名备案山东德州如何网站建设教程
  • 狠狠做网站改成什么了有什么网站可以做推广
  • 网站开发标书范本平面设计师长逛的网站有哪些
  • 哈尔滨做网站公司哪家好定制开发app多少钱
  • 做网站公司商丘wordpress 特效主题
  • 一个人做网站用什么技术知名企业网站
  • 高淳建设发展集团网站电脑上买wordpress
  • 江西南昌网站制作手机推广平台有哪些
  • 江门网站建设 卓华江苏新宁建设集团网站
  • 有了自己的网站怎么赚钱wordpress图册主题
  • 网站建设哪个好一些门户网站怎么做seo
  • 吕梁建设机械网站合肥市城乡建设局2019网站
  • 怎么做单页网站网站开发项目怎么接
  • 可以做外链网站如何在国外网站做翻译兼职
  • 门户网站手机版机构网站建设
  • 建设小说网站用什么软件下载前端招聘网站
  • 怎么建设外贸网站域名停域免费观看软件
  • 九五至尊娱乐场网站网站导航效果
  • 东莞官方网站设计学做甜点的网站