Here you can find the source of substr(String str, int length)
Parameter | Description |
---|---|
str | a parameter |
length | a parameter |
public static String substr(String str, int length)
//package com.java2s; public class Main { /**/*from w ww . j a v a2 s. co m*/ * safe substring, without exception * @param str * @param length * @return * @author <a href="mailto:iffiff1@gmail.com">Tyler Chen</a> * @since 2014-9-25 */ public static String substr(String str, int length) { if (str == null) { return str; } if (length < str.length()) { return str.substring(0, length); } return str; } }