java中的字符串操作有:length()函数,计算字符串的长度;2.isEmpty()函数,判断字符串是否为空;3.concat()函数,将指定的字符串参数连接到字符串;4.hashCode()函数,返回字符串的哈希码;java
java中的字符串操作有:length()函数,计算字符串的长度;2.isEmpty()函数,判断字符串是否为空;3.concat()函数,将指定的字符串参数连接到字符串;4.hashCode()函数,返回字符串的哈希码;
java中的字符串操作有以下几种
length()函数
java中length()函数的作用是用于计算字符串的长度。
String Str = new String("Hello world!");
System.out.println(Str.length()); //返回 12
isEmpty()函数
java中isEmpty()函数的作用是用于判断字符串是否为空。
String myStr1 = "Runoob";
String myStr2 = "";
System.out.println(myStr1.isEmpty()); //返回 false
System.out.println(myStr2.isEmpty()); //返回 true
concat()函数
java中concat()函数的作用是用于将指定的字符串参数连接到字符串中。
String s = "Hello";
s = s.concat(" world!");
System.out.println(s);
输出结果为:
Hello world!
hashCode()函数
java中hashCode()函数的作用是用于返回字符串的哈希码。
String Str = new String("Hello world!");
System.out.println(Str.hashCode());
--结束END--
本文标题: java字符串操作有哪些
本文链接: https://www.lsjlt.com/news/111188.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-19
2024-04-19
2024-04-19
2024-04-19
2024-04-19
2024-04-19
2024-04-19
2024-04-19
2024-04-19
2024-04-19
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0