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

重庆龙华网站建设公司店铺推广平台有哪些

重庆龙华网站建设公司,店铺推广平台有哪些,wordpress插件内链,杭州官网包装类 wrapper 装箱与拆箱 装箱&#xff1a;基本类型->包装类&#xff1b; 拆箱&#xff1a; 包装类->基本类型 public class Integer01 {public static void main(String[] args) {//演示int <--> Integer 的装箱和拆箱//jdk5前是手动装箱和拆箱//手动装箱 in…

包装类

wrapper

装箱与拆箱

  • 装箱:基本类型->包装类; 拆箱: 包装类->基本类型
 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()方法}}

如果频繁拆装箱的话,也会严重影响系统的性能。我们应该尽量避免不必要的拆装箱操作。

8种包装类

针对8种基本数据类型相应的引用类型——包装类

基本数据类型包装类
byteByte
shortShort
intInteger
longLong
charCharacter
floatFloat
doubleDouble
booleanBoolean

所有包装类都是抽象类Number的子类

缓存机制

Java 基本数据类型的包装类型的大部分都用到了缓存机制来提升性能。

Byte,Short,Integer,Long 这 4 种包装类默认创建了数值 [-128,127] 的相应类型的缓存数据,

只有自动装箱的才有缓存

Character 创建了数值在 [0,127] 范围的缓存数据,
Boolean 直接返回 True or False
两种浮点数类型的包装类 Float,Double 并没有实现缓存机制。

Integer a1=new Integer(1);  
Integer a2=new Integer(1);  
System.out.println(a1==a2);//false  Integer b1=2;  
Integer b2=2;  
System.out.println(b1==b2);//true,在[-128,127]之间的自动装箱valueOf使用了缓冲机制,不会创建新的对象  Integer c1=200;  
Integer c2=200;  
System.out.println(c1==c2);//false  
//因此,包装类对象的比较要用equals
System.out.println(c1.equals(c2));//trueBoolean d1=true;  
Boolean d2=true;  
System.out.println(d1==d2);//true

Integer 缓存源码:

public static Integer valueOf(int i) {if (i >= IntegerCache.low && i <= IntegerCache.high)return IntegerCache.cache[i + (-IntegerCache.low)];return new Integer(i);
}
private static class IntegerCache {static final int low = -128;static final int high;static {// high value may be configured by propertyint h = 127;}
}

Character 缓存源码:

public static Character valueOf(char c) {if (c <= 127) { // must cachereturn CharacterCache.cache[(int)c];}return new Character(c);
}private static class CharacterCache {private CharacterCache(){}static final Character cache[] = new Character[127 + 1];static {for (int i = 0; i < cache.length; i++)cache[i] = new Character((char)i);}}

如果超出对应范围仍然会去创建新的对象,缓存的范围区间的大小只是在性能和资源之间的权衡。

常用方法

在这里插入图片描述

  1. Number子类实现的方法
MethodDescription
byte byteValue() , short shortValue(), int intValue() , long longValue(), float floatValue(), double doubleValue()Converts the value of this Number object to the primitive data type returned.
把包装类对象转换成基本数据类型
int compareTo(Byte anotherByte) , int compareTo(Double anotherDouble), int compareTo(Float anotherFloat), int compareTo(Integer anotherInteger), int compareTo(Long anotherLong), int compareTo(Short anotherShort)Compares this Number object to the argument.
比较函数
boolean equals(Object obj)Determines whether this number object is equal to the argument. The methods return true if the argument is not null and is an object of the same type and with the same numeric value. There are some extra requirements for Double and Float objects that are described in the Java API documentation.
是否相等

Integer的方法

MethodDescription
static Integer decode(String s)Decodes a string into an integer. Can accept string representations of decimal, octal, or hexadecimal numbers as input.
static int parseInt(String s)Returns an integer (decimal only).
static int parseInt(String s, int radix)Returns an integer, given a string representation of decimal, binary, octal, or hexadecimal (radix equals 10, 2, 8, or 16 respectively) numbers as input.
String toString()Returns a String object representing the value of this Integer.
static String toString(int i)Returns a String object representing the specified integer.
static Integer valueOf(int i)Returns an Integer object holding the value of the specified primitive.
static Integer valueOf(String s)Returns an Integer object holding the value of the specified string representation.
static Integer valueOf(String s, int radix)Returns an Integer object holding the integer value of the specified string representation, parsed with the value of radix. For example, if s = “333” and radix = 8, the method returns the base-ten integer equivalent of the octal number 333.

eg

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'));//转成小写}
}
http://www.rdtb.cn/news/20672.html

相关文章:

  • 企业设备管理系统seo外链软件
  • 江苏省内网站建设百度app内打开
  • 深圳分销网站设计电话2022年最近十大新闻
  • 一流的微商城网站建设seo网站优化案例
  • 婚介网站模板怎么从网上找客户
  • 政府手机网站今日最新国际新闻
  • 网站建设公司如何发展网络游戏推广员是做什么的
  • 企业网站的技术维护内容主要包括媒体营销平台
  • 专业做全景图的网站平台投资网站建设方案
  • 做彩票网站需要多少钱国内重大新闻
  • 手机app开发 网站建设360收录入口
  • 做签证的网站全球疫情最新数据统计
  • 清爽帝国cms沈阳seo网站关键词优化
  • 聊城网站建设售后服务游戏行业seo整站优化
  • 福州网站建设多少钱湖南今日新闻最新头条
  • 建设肯德基网站的好处seo优化网站的手段
  • 佛山优化公司推广长沙seo优化首选
  • 网站如果直接点击拨打电话爱链接
  • 做网站和论坛区别免费网络推广的方法
  • 做网站东莞东莞建网站交换链接案例
  • 河北省两学一做网站国外市场网站推广公司
  • java做网站需要的接口推广平台排行榜app
  • 江都区城乡建设局网站马局360优化大师官方网站
  • 如何将网站让百度收录企业网站设计图片
  • asp做网站缺点关键词名词解释
  • 呼和浩特做网站哪家公司好淘宝如何提升关键词排名
  • 网站设计大概在什么价位培训心得体会怎么写
  • 衢州做网站的公司免费网站建站平台
  • 怎样如何做网站赚钱关键词工具
  • 商城网站功能表网站如何被搜索引擎收录