您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Java 实例 - 字符串比较

2024/4/23 8:26:47发布12次查看
以下实例中我们通过字符串函数 compareto (string) ,comparetoignorecase(string) 及 compareto(object string) 来比较两个字符串,并返回字符串中第一个字母ascii的差值。
实例代码如下:
//stringcompareemp.java 文件public class stringcompareemp{ public static void main(string args[]){ string str = "hello world"; string anotherstring = "hello world"; object objstr = str; system.out.println( str.compareto(anotherstring) ); system.out.println( str.comparetoignorecase(anotherstring) ); //忽略大小写 system.out.println( str.compareto(objstr.tostring())); }}
以上代码实例输出结果为:
-32 0 0
以上就是java 实例 - 字符串比较的内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product