Skip to content

Instantly share code, notes, and snippets.

@EdgeJH
Last active June 24, 2020 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdgeJH/f3ed01c75be1cff7ea323e4d19e0687d to your computer and use it in GitHub Desktop.
Save EdgeJH/f3ed01c75be1cff7ea323e4d19e0687d to your computer and use it in GitHub Desktop.
public final class ListUtils {
private ListUtils() {
}
public static <T> T getFirst( final List<T> list ) {
return getFirst( list, null );
}
public static <T> T getLast( final List<T> list ) {
return getLast( list, null );
}
private static <T> T getFirst( final List<T> list, final T t ) {
return isEmpty( list ) ? t : list.get( 0 );
}
private static <T> T getLast( final List<T> list, final T t ) {
return isEmpty( list ) ? t : list.get( list.size() - 1 );
}
public static <T> boolean isEmpty( final List<T> list ) {
return list == null || list.isEmpty();
}
public static <T> boolean isNotEmpty( final List<T> list ) {
return list != null && !list.isEmpty();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment