正在加载图片...
编程红宝书(珍藏版) ava 完金自学手册 5.2.2比较字符串 比较字符串实现两个字符串内容是否相同的比较结果,如果相 同则返回true,如果不同则返回 false。Java调用 String类的 equals函数实现,该函数的参数是一个 Stringi对象,返回值 是 boolean值(比较后的结果)。 1 String s1= new String("hello") //创建 个字符串,内容为” hello”,字符串名为s1 2 String s2= new String("world") //创建 个字符串,内容为” world”,字符串名为s String s3= sl concat(s2) //调用 String类的 concat函数实现字符串的连接 4 String s4="helloworld //创建 个字符串,内容为” helloworld”,字符串名为s4 5 System.out. printin(sl. equals(s2));//输入比较结果, 结果为 false 6 System.out. printIn(s3. equals(s4);//输入比较结果, 结果为true Q 机械工业出版社 China Machine Press5.2.2 比较字符串 • 比较字符串实现两个字符串内容是否相同的比较结果,如果相 同则返回true,如果不同则返回false。Java调用String类的 equals()函数实现,该函数的参数是一个String对象,返回值 是boolean值(比较后的结果)。 • 1 String s1 = new String(“hello”); //创建 一个字符串,内容为”hello”,字符串名为s1 • 2 String s2 = new String(“world”); //创建 一个字符串,内容为”world”,字符串名为s2 • 3 String s3 = s1.concat(s2); //调用 String类的concat函数实现字符串的连接 • 4 String s4 = “helloworld”; //创建一 个字符串,内容为”helloworld”,字符串名为s4 • 5 System.out.println(s1.equals(s2));//输入比较结果, 结果为false • 6 System.out.println(s3.equals(s4)); //输入比较结果, 结果为true
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有