Here you can find the source of left(String str, int size)
public static String left(String str, int size)
//package com.java2s; //License from project: Apache License public class Main { public static String left(String str, int size) { if (str == null || "".equals(str)) { return str; }//from ww w . j a va 2 s .c o m if (size > 0) { if (size > str.length()) { return str; } else { return str.substring(0, size); } } else if (size == 0) { return ""; } else { size = -size; if (size > str.length()) { return str; } return str.substring(str.length() - size); } } }