Skip to content

Instantly share code, notes, and snippets.

@sharif2008
Last active May 6, 2016 07:59
Show Gist options
  • Save sharif2008/59f5854e6c962cd23a161b84199e1c9d to your computer and use it in GitHub Desktop.
Save sharif2008/59f5854e6c962cd23a161b84199e1c9d to your computer and use it in GitHub Desktop.
Get a substring with N character in JAVA
public static final String getNcharacters(int n, String s){
if(s==null)
return "";
return s.substring(0, Math.min(s.length(), n));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment