Skip to content

Instantly share code, notes, and snippets.

@knoxknox
Created June 5, 2016 14:18
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 knoxknox/fd82e4d45d9668a8059a9261d4424b70 to your computer and use it in GitHub Desktop.
Save knoxknox/fd82e4d45d9668a8059a9261d4424b70 to your computer and use it in GitHub Desktop.
// create a mutable set
Set<String> set = Sets.newHashSet("Jay", "Betsy");
// create an immutable set
Set<String> set = ImmutableSet.of("Jay", "Betsy", "Jenny");
// create a mutable list
List<String> list = Lists.newArrayList("Jay", "Betsy");
// create an immutable list
List<String> list = ImmutableList.of("Jay", "Betsy", "Jenny");
// create a mutable map
Map<Integer, String> map = Maps.newHashMap(ImmutableMap.of(1, "Jay", 2, "Betsy"));
// create an immutable map
Map<Integer, String> map = ImmutableMap.of(1, "Jay", 2, "Betsy", 3, "Jenny", 4, "Joe");
// create an immutable map (builder)
Map<Integer, String> map = ImmutableMap.<Integer, String> builder().put(1, "Jay").put(2, "Betsy").build();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment