(JAVA)Object类之String类
生活随笔
收集整理的這篇文章主要介紹了
(JAVA)Object类之String类
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
/*
字符串:
一、概述:1.字符串在JAVA中,使用""表示2.java.lang.String類3.只要寫""就是字符串對象。不需要new二、空參構(gòu)造器new Sting();private final char value[];public String() {this.value = "".value;}
三、String類一個參數(shù)構(gòu)造器:字節(jié)數(shù)組采用平臺(操作系統(tǒng))默認(rèn)字符集解碼數(shù)組--編碼表GBKbyte[] = {};將字節(jié)數(shù)組轉(zhuǎn)成字符串public String(byte bytes[]) {this(bytes, 0, bytes.length);}
四、String類兩個參數(shù)構(gòu)造器:指定一個編碼表【I/O更新】五、String類三個參數(shù)構(gòu)造器:字節(jié)數(shù)組,開始下標(biāo),獲取幾個
java.lang.String @Contract(pure = true)
public String(@NotNull byte[] bytes,int offset,int length)
六、String類一個參數(shù)構(gòu)造器:字符數(shù)組
public String(char value[]) {this.value = Arrays.copyOf(value, value.length);}
七、String類三個參數(shù)構(gòu)造器:字符數(shù)組,開始下標(biāo),獲取幾個public String(char value[], int offset, int count) {if (offset < 0) {throw new StringIndexOutOfBoundsException(offset);}if (count <= 0) {if (count < 0) {throw new StringIndexOutOfBoundsException(count);}if (offset <= value.length) {this.value = "".value;return;}}// Note: offset or count might be near -1>>>1.if (offset > value.length - count) {throw new StringIndexOutOfBoundsException(offset + count);}this.value = Arrays.copyOfRange(value, offset, offset+count);}
八、String類三個參數(shù)構(gòu)造器:整數(shù)數(shù)組,開始下標(biāo),獲取幾個(基本不用)
九、 String類三個參數(shù)構(gòu)造器:字符串(基本不用)
public String(String original) {this.value = original.value;this.hash = original.hash;}十、字符串一旦創(chuàng)建,就是常量,不能修改。
"abc"是對象---不能改變
s 是引用型變量
s 的指向?qū)ο罂梢愿淖兪弧⒃诙阎?#xff0c;如果
String s1 = new String('a','b','c');
String s2 = new String('a','b','c');
System.out.println(s1==s2);-------true但
String s3 = new String("abc");
String s4 = "abc";
System.out.println(s1==s2);-------Fals:創(chuàng)建對象不同String s5 = "efg";
System.out.println(s4==(s4+s5));---- f-------常量與變量相加,不知道結(jié)果,重新建立空間,比較的是內(nèi)存地址
System.out.println(s4==("abc"+"def"));---- t------常量與常量相加,比較的是具體數(shù)值*/
1.雙引號代表String類對象
2.String類空參構(gòu)造器
3.String類一個參數(shù)構(gòu)造器?
?
?
?
?
?
總結(jié)
以上是生活随笔為你收集整理的(JAVA)Object类之String类的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python时间处理模块有哪些_Pyth
- 下一篇: 1052. 卖个萌 (20)