String的substring()的用法总结

String的substring()的用法总结

    substring() 方法返回字符串的子字符串。
    1.public String substring(int beginIndex)  :截取 索引位置beginIndex(包括)  到 字符串最后

    2.public String substring(int beginIndex, int endIndex)  :截取 索引位置beginIndex(包括)  到 索引位置endIndex (不包括)

  参数
    beginIndex -- 起始索引(包括)。

    endIndex -- 结束索引(不包括)。

  返回值
    子字符串。
 实例
public class Test {
    public static void main(String args[]) {
    	String Str = new String("www.51gjie.com");

    	System.out.print("返回值 :" );
    	System.out.println(Str.substring(4) );

    	System.out.print("返回值 :" );
    	System.out.println(Str.substring(4, 6) );
	}
}

原文地址:https://www.cnblogs.com/xiao-bu/p/14316589.html