Java String Sub String substring(String source, int startIndex)

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

Description

substring

License

Open Source License

Declaration

public static String substring(String source, int startIndex) 

Method Source Code

//package com.java2s;

public class Main {

    public static String substring(String source, int startIndex) {
        if (source == null)
            return null;
        int length = source.length();
        if (startIndex < 0)
            startIndex = 0;/* w w  w  .j a  v  a 2s .com*/
        if (length < startIndex)
            return "";
        else
            return source.substring(startIndex);
    }

    public static String substring(String source, int startIndex, int endIndex) {
        if (source == null)
            return null;
        int length = source.length();
        if (startIndex < 0)
            startIndex = 0;
        if (startIndex >= endIndex)
            return "";
        else if (length < startIndex)
            return "";
        else if (length < endIndex)
            return source.substring(startIndex, length - 1);
        else
            return source.substring(startIndex, endIndex);
    }
}

Related

  1. substring(String self, Integer startIndex, Integer endIndex)
  2. substring(String source, int beginIndex, int endIndex)
  3. substring(String source, int length, String padding)
  4. substring(String source, int offset, int dataLength)
  5. substring(String source, int size)
  6. subString(String source, int startIndex, int count)
  7. substring(String src, int beginIndex, int endIndex)
  8. substring(String src, int start_idx, int end_idx)
  9. subString(String src, int startIndex, int endIndex)