java基础之根本数据类型对象包装类,StringBuffer

java基础之基本数据类型对象包装类,StringBuffer

基本数据类型对象包装类:

 

Bytebyte

Shortshort

Integerint

Longlong

Booleanboolean

Folatfolat

Doubledouble

Characterchar

 

基本数据类型对象包装类的最常见作用,

就是用于基本数据类型和字符串类型之间做转换

基本数据类型转换成字符串:

基本数据类型+“ ”

基本数据类型 .  toString(基本数据类型值);

如:IntergertoString34);//34整数变成“34”;

字符串专程基本数据类型:

xxx   a    =  Xxx . parseXxxString);

int  a    =  Integer  .  parseInt(”123“);

double b   =  Double  .  parseDouble(”12.23“);

boolean b   =  Boolean  .  parseBoolean(”true“);

 

十进制转换其他进制:

toBinaryString();

toHexString();

toOCtalString();

其他进制转成十进制:

parseIntstringradix);

byte数值最大为127

Integer a=128  Integer b=128  a==b 返回false 

Integer c=127  Integer d=127  c==d 返回true

 

 

 

 

 

StringBuffer(常见功能-添加)

 

StringBuffer是字符串缓冲区。   是一个容器。

特点:

<!--[if !supportLists]-->1.<!--[endif]-->长度是可变化的。

<!--[if !supportLists]-->2.<!--[endif]-->可以直接操作多个数据类型。

<!--[if !supportLists]-->3.<!--[endif]-->最终会通过toString方法变成字符串。

C create  U update  R read  D delete

<!--[if !supportLists]-->1.<!--[endif]-->存储

<!--[if !supportLists]-->a) <!--[endif]-->StringBuffer append():将指定数据作为参数添加到已经数据结尾处。

<!--[if !supportLists]-->b) <!--[endif]-->StringBuffer insertindex,数据):可以将数据插入到指定index位置。

<!--[if !supportLists]-->2.<!--[endif]-->删除

<!--[if !supportLists]-->a) <!--[endif]-->SringBuffer delete(start,end):删除缓冲区中的数据,包含start,不包含end

<!--[if !supportLists]-->b) <!--[endif]-->StringBuffer deleteindex):删除指定位置的字符。

<!--[if !supportLists]-->3.<!--[endif]-->获取

<!--[if !supportLists]-->a) <!--[endif]-->Char charAtint index

<!--[if !supportLists]-->b) <!--[endif]-->Int indexofString str

<!--[if !supportLists]-->c) <!--[endif]-->Int lastIndexof(String str)

<!--[if !supportLists]-->d) <!--[endif]-->Int length()

<!--[if !supportLists]-->e) <!--[endif]-->String substringint startint end

<!--[if !supportLists]-->4.<!--[endif]-->修改

<!--[if !supportLists]-->a) <!--[endif]-->StringBuffer replacestartendstring);

<!--[if !supportLists]-->b) <!--[endif]-->Void setCharAtint indexchar ch);

<!--[if !supportLists]-->5.<!--[endif]-->反转

<!--[if !supportLists]-->a) <!--[endif]-->StringBuffer  reverse();

6将缓冲区中指定数据存储到指定字符数组中

void getCharsint srcBeginint srcEndchar【】 dstint dstBegin

 

JDK1.5版本之后出现了StringBuilder

StringBuffer是线程同步。

StringBuilder是线程不同步。

以后开发,建议使用StringBuilder

Java升级三个因素:

<!--[if !supportLists]-->1.<!--[endif]-->提高效率。

<!--[if !supportLists]-->2.<!--[endif]-->简化书写。

<!--[if !supportLists]-->3.<!--[endif]-->提高安全性。

 

<!--EndFragment-->