Skip to content

Instantly share code, notes, and snippets.

@justinmusgrove
Last active December 22, 2015 06:09
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 justinmusgrove/6428883 to your computer and use it in GitHub Desktop.
Save justinmusgrove/6428883 to your computer and use it in GitHub Desktop.
#java
List<String> strings = new ArrayList<String>();
strings.add("one");
strings.add("two");
strings.add("three");
String firstElement = null;
if (!strings.isEmpty() && strings.size() == 1) {
firstElement = strings.get(0);
}
List<String> strings = Lists.newArrayList("one", "two", "three");
String firstElement = Iterables.getFirst(strings, null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment