Java String Sub String substring(String str, int start)

Here you can find the source of substring(String str, int start)

Description

substring

License

Open Source License

Declaration

public static String substring(String str, int start) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String substring(String str, int start) {
        if (str == null)
            return null;

        if (start < 0)
            start = str.length() + start;
        if (start < 0)
            start = 0;/* w  w  w . ja v  a  2  s  . c  o m*/

        return (start > str.length()) ? "" : str.substring(start);
    }

    public static String substring(String str, int start, int end) {
        if (str == null)
            return null;

        if (end < 0)
            end = str.length() + end;
        if (start < 0)
            start = str.length() + start;
        if (end > str.length())
            end = str.length();
        if (start > end)
            return "";
        if (start < 0)
            start = 0;
        if (end < 0)
            end = 0;

        return str.substring(start, end);
    }

    public static int length(String str) {
        return str == null ? 0 : str.length();
    }
}

Related

  1. subString(String str, int len)
  2. substring(String str, int len)
  3. subString(String str, int num, String token)
  4. substring(String str, int off, int len)
  5. subString(String str, int offset, int leng)
  6. substring(String str, int start)
  7. substring(String str, int start)
  8. subString(String str, int start, int end)
  9. substring(String str, int start, int end)