Skip to content

Instantly share code, notes, and snippets.

@dlew
Created September 13, 2013 18:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dlew/6554307 to your computer and use it in GitHub Desktop.
Save dlew/6554307 to your computer and use it in GitHub Desktop.
public class LazyListManagerUtils {
public static <T> List<T> add(List<T> list, T item) {
if (list == null) {
list = new ArrayList<T>();
list.add(item);
}
else if (!list.contains(item)) {
list.add(item);
}
return list;
}
public static <T> List<T> remove(List<T> list, T item) {
if (list != null) {
list.remove(item);
if (list.isEmpty()) {
list = null;
}
}
return list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment