Book Image

Getting Started with Hazelcast, Second Edition

By : Matthew Johns
Book Image

Getting Started with Hazelcast, Second Edition

By: Matthew Johns

Overview of this book

Table of Contents (19 chapters)
Getting Started with Hazelcast Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Sets, lists, and queues


In the previous examples, we looked at key-value storage provided by Hazelcast maps. However, there are a number of other collections that provide keyless groups of objects. Two of these additional types are distributed versions of collections that you may be already familiar with—sets and lists.

The primary difference between these two collections is that lists allow for multiple entries and a set does not. So, if we add them to the previous map example, we will get the following code:

Set<String> cities = hz.getSet("cities");
cities.addAll(captials.values());
cities.add("London");
cities.add("Rome");
cities.add("New York");

List<String> countries = hz.getList("countries");
countries.addAll(captials.keySet());
countries.add("CA");
countries.add("DE");
countries.add("GB"); // duplicate entry

When using the test console again to interact with these new collections, we will have to use different commands, as we are now interacting with a set and a list rather...