Last active
June 24, 2020 08:00
-
-
Save EdgeJH/f3ed01c75be1cff7ea323e4d19e0687d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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