String 类提供了连接两个字符串的方法:
string1.concat(string2);
返回 string2 连接 string1 的新字符串。也可以对字符串常量使用 concat() 方法,如:
更常用的是使用'+'操作符来连接字符串,如:
结果如下:
charAt() 方法用于返回指定索引处的字符。索引范围为从 0 到 length() - 1。
public class Test { public static void main(String args[])
{ String s = "www.runoob.com";
char result = s.charAt(6);
System.out.println(result); } }
以上程序执行结果为:
{ String Str = new String("菜鸟教程:www.runoob.com");
boolean retVal;
retVal = Str.endsWith( "runoob" );
System.out.println("返回值 = " + retVal ); retVal = Str.endsWith( "com" );
System.out.println("返回值 = " + retVal ); } }
public class Main { public static void main(String[] args)
{ String myStr = "Runoob";
System.out.println(myStr.contains("Run"));
System.out.println(myStr.contains("o"));
System.out.println(myStr.contains("s")); } }