Java String Sub String substring(String str, int beginIndex, int endIndex)

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

Description

Index safe substring operation.

License

Open Source License

Parameter

Parameter Description
str The string.
beginIndex The begin index.
endIndex The end index.

Return

The substring.

Declaration

public static String substring(String str, int beginIndex, int endIndex) 

Method Source Code

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

public class Main {
    /**//from ww  w  . j  a v  a  2 s.c o  m
     * Index safe substring operation.
     * 
     * @param str The string.
     * @param beginIndex The begin index.
     * @param endIndex The end index.
     * @return The substring.
     */
    public static String substring(String str, int beginIndex, int endIndex) {
        if (beginIndex < 0) {
            beginIndex = 0;
        }
        if (endIndex > str.length()) {
            endIndex = str.length();
        }
        return str.substring(beginIndex, endIndex);
    }
}

Related

  1. subString(String srcStr, int subLen)
  2. substring(String str, char pattern)
  3. substring(String str, int beginIndex)
  4. substring(String str, int beginIndex, int endIndex)
  5. subString(String str, int beginIndex, int endIndex)
  6. substring(String str, int beginIndex, int len)
  7. subString(String str, int end)
  8. substring(String str, int index, int length)
  9. subString(String str, int len)