Skip to content

Instantly share code, notes, and snippets.

@amihalik
Last active April 2, 2018 18:38
Show Gist options
  • Save amihalik/e6c85e88ec48873ef9b6259b84ddbd83 to your computer and use it in GitHub Desktop.
Save amihalik/e6c85e88ec48873ef9b6259b84ddbd83 to your computer and use it in GitHub Desktop.
Six String example
public class foo {
public static void main(String[] args) throws Exception {
String long_string = "asdfasdf123456";
String six_string = "123456";
String five_string = "12345";
String one_string = "1";
String empty_string = "";
System.out.println(six_string(long_string));
System.out.println(six_string(six_string));
System.out.println(six_string(five_string));
System.out.println(six_string(one_string));
System.out.println(six_string(empty_string));
}
public static String six_string(String str){
return str.substring(Math.max(0, str.length()-6), str.length());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment