当前位置:首页 > 千层云服务器 > 正文

java字符串操作有哪些

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());

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

在线客服