Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions

A string-specific set of utilities.

Dhanji R. Prasanna (
 public class Strings {
   private Strings() {

Tests for null or emptiness of a string, throwing an java.lang.IllegalArgumentException if one is encountered.

aString Any string to test for emptiness.
message A message to throw inside an IllegalArgumentException if the aString was empty.
  public static void nonEmpty(String aStringString message) {
    if (empty(aString))
      throw new IllegalArgumentException(message);


string Any string to test for emptiness.
True if this string is empty or null.
  public static boolean empty(String string) {
    return null == string || "".equals(string.trim());
  public static String join(String[] stringschar sep) {
    StringBuilder builder = new StringBuilder();
    for (String string : strings) {
    builder.deleteCharAt(builder.length() - 1);
    return builder.toString();
New to GrepCode? Check out our FAQ X