Here you can find the source of left(String s, int len)
Parameter | Description |
---|---|
s | The string to get the leftmost characters from |
len | The length of the required string |
public static String left(String s, int len)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w . ja v a 2s. co m*/ * Gets the leftmost n characters of a string. If n characters are not * available, or the string is null, the string will be returned without an * exception. * * @param s * The string to get the leftmost characters from * @param len * The length of the required string * @return The leftmost characters */ public static String left(String s, int len) { if (len < 0) throw new IllegalArgumentException("Requested String length " + len + " is less than zero"); return ((s == null) || (s.length() <= len)) ? s : s.substring(0, len); } }