String構造方法

2021-09-23 13:35:23 字數 1056 閱讀 8075

scanner s=new scanner(system.in);

int i=s.nextint();

string s=s.nextline();

system.out.println(i+s);

對於上面這段**,如果我們在控制台輸入10並接著按下回車 那麼輸出語句就只會有乙個10

這是因為 nextline()函式接收一行字串,並且以\r\n結束,所以在我們上述輸入時,得不到應有的字串輸入.

「***」 相當於乙個string物件,可以呼叫其方法

是乙個常量,一旦被賦值就不能改變,

初始化新建立的 string物件,使其表示空字串行。

string(byte bytes)

通過使用平台的預設字符集解碼指定的位元組陣列來構造新的 string 。

通過使用平台的預設字符集解碼指定的位元組子陣列來構造新的 string 。

分配乙個新的 string ,以便它表示當前包含在字元陣列引數中的字串行。

分配乙個新的 string ,其中包含字元陣列引數的子陣列中的字元

這個和上面類似

String類的構造方法

字串是常量,一旦被賦值,其值不能在改變 常用的構造方法 public string 無參構造 public string byte bytes 將位元組陣列轉換成字串 public string byte bytes,int offset,int length 將位元組陣列的一部分轉換成字串 pub...

String類的構造方法

string s1 hello world system.out.println s1 hello world byte bytes 97是a,98是b,99是c string s2 newstring bytes system.out.println s2 輸出結果 abcs1變數中儲存的僅僅是乙...

String類的構造方法

public class stringdemo2 strign char value 傳遞字元陣列 將字元陣列轉換為字串 字元陣列引數不查詢編碼表 string char valuie,int offeset,int count offeset代表陣列開始的索引 count 代表個數 public ...