關於java String的簡單概要

2021-07-11 19:36:20 字數 544 閱讀 5548

new string()和new string(」」)都是申明乙個新的空字串,是空串不是null

1. string a=」a」; strig c=」a」;輸出比較是true

2.string b=new string (「b」);string c=new string (「b」);輸出比較是false

進行區別概述,1只建立了乙個字元在常量,存放在常量池裡面,只有乙個引用哦。2建立了兩個物件,乙個是」b」通過」「雙引號建立的,另乙個是通過new建立的.只不過他們建立的時期不同,

乙個是編譯期,乙個是執行期

string a = 「ab」;

string bb = 「b」;

string b = 「a」+ bb; //編譯器不能確定為常量

system.out.println(a==b);

下乙個內容,string是不可變的,因為是public final class。

一般變化較多的時候使用strigbuffer 或者 stringbuildder。、

這兩個區別,多執行緒與單執行緒。

JAVA string常用的操作

class stringmethoddemo public static void method sub public static void method split public static void method replace public static void method trans...

Java String的常用方法

public char charat int index 返回指定索引處的字元。public int compareto string anotherstring public int comparetoignorecase string str 比較兩個字串的字典順序。比較兩個字串按字典順序,不區...

Java string的基本用法

一,定義字串與子串 定義string e 空字串 string e hello 提取子串使用substring方法 string e hello string s e.substring 0,4 s等於hell system.out.println s string e hello string f...