温馨提示×

java字符串操作有哪些

养鱼的猫咪
168
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