code: public static String lpad(String base, int len, String pad) {
  		if (len < 0 || "".equals(pad)) {
  			return null;
  		} else if (len == 0) {
  			return "";
  		}
  
  		char[] data = new char[len];
  		char[] baseChars = base.toCharArray();
  		char[] padChars = pad.toCharArray();
  
  		// the length of the padding needed
  		int pos = Math.max(len - base.length(), 0);
  
  		// copy the padding
  		for (int i = 0; i < pos; i += pad.length()) {
  			for (int j = 0; j < pad.length() && j < pos - i; j++) {
  				data[i + j] = padChars[j];
  			}
  		}
  
  		// copy the base
  		int i = 0;
  		while (pos + i < len && i < base.length()) {
  			data[pos + i] = baseChars[i];
  			i += 1;
  		}
  
  		return new String(data);
  	}
docs: Returns the string str left-padded with the string pad to a length of len characters.
  If str is longer than len, the return value is shortened to len characters.