Java tutorial
//package com.java2s; public class Main { public static String right(String s, int chars) { String t = s; if (null == t) t = ""; String retval = new String(t); int len = retval.length(); if (len > chars) { try { retval = retval.substring(len - chars, len); } catch (Exception e) { // shouldn't ever happen ... but return original string in case } } return retval; } }