溫馨提示×

java字符串操作有哪些

養魚的貓咪
180
2021-04-19 11:50:15
欄目: 編程語言

java中的字符串操作有:length()函數,計算字符串的長度;2.isEmpty()函數,判斷字符串是否為空;3.concat()函數,將指定的字符串參數連接到字符串;4.hashCode()函數,返回字符串的哈希碼;

java字符串操作有哪些

java中的字符串操作有以下幾種

1.length()函數

java中length()函數的作用是用于計算字符串的長度。

String Str = new String("Hello world!");

System.out.println(Str.length()); //返回 12

2.isEmpty()函數

java中isEmpty()函數的作用是用于判斷字符串是否為空。

String myStr1 = "Runoob";

String myStr2 = "";

System.out.println(myStr1.isEmpty()); //返回 false

System.out.println(myStr2.isEmpty()); //返回 true

3.concat()函數

java中concat()函數的作用是用于將指定的字符串參數連接到字符串中。

String s = "Hello";

s = s.concat(" world!");

System.out.println(s);

輸出結果為:

Hello world!

4.hashCode()函數

java中hashCode()函數的作用是用于返回字符串的哈希碼。

String Str = new String("Hello world!");

System.out.println(Str.hashCode());

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女