A newer version of this documentation is available.

View Latest

Data Structures Reference

      +
      You can use complex data structures such as dictionaries and lists in Couchbase.

      Data structures in Couchbase are similar in concept to data structures in the Java Collections Framework:

      See our Data Model pages.

      Here is a list of common operations:

      Table 1. Data Structure Operations

      mapAdd

      Add a key to the map.

          map.put("some_key", "value");
          // #end::data_structures_1[];
        }
      
        public void data_structures_2() throws Exception {
          map.remove("some_key");
          // #end::data_structures_2[];
        }
      
        public void data_structures_3() throws Exception {
          map.get("some_key"); //=> value
          // #end::data_structures_3[];
        }
      
        public void data_structures_4() throws Exception {
          arrayList.add(1234);
          // #end::data_structures_4[];
        }
      
        public void data_structures_5() throws Exception {
          arrayList.add(0, "hello world");
          // #end::data_structures_5[];
        }
      
        public void data_structures_6() throws Exception {
          arrayList.remove(1);
          // #end::data_structures_6[];
        }
      
        public void data_structures_7() throws Exception {
          arrayList.set(0, "first value");
          // #end::data_structures_7[];
        }
      
        public void data_structures_8() throws Exception {
          arrayList.get(0);
          // #end::data_structures_8[];
        }
      
        public void data_structures_9() throws Exception {
          arraySet.add("some_value");
          // #end::data_structures_9[];
        }
      
        public void data_structures_10() throws Exception {
          Set set = arraySet;
          // #end::data_structures_10[];
        }
      
        public void data_structures_11() throws Exception {
          arraySet.contains("value");
          // #end::data_structures_11[];
        }
      
        public void data_structures_12() throws Exception {
          arraySet.remove("some_value");
          // #end::data_structures_12[];
        }
      
        public void data_structures_13() throws Exception {
          queue.add("job123");
          // #end::data_structures_13[];
        }
      
        public void data_structures_14() throws Exception {
          Object item = queue.poll(); //=> "job123"
          // #end::data_structures_14[];
        }
      
        public void data_structures_15() throws Exception {
          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      mapRemove

      Remove a key from a map.

          map.remove("some_key");
          // #end::data_structures_2[];
        }
      
        public void data_structures_3() throws Exception {
          map.get("some_key"); //=> value
          // #end::data_structures_3[];
        }
      
        public void data_structures_4() throws Exception {
          arrayList.add(1234);
          // #end::data_structures_4[];
        }
      
        public void data_structures_5() throws Exception {
          arrayList.add(0, "hello world");
          // #end::data_structures_5[];
        }
      
        public void data_structures_6() throws Exception {
          arrayList.remove(1);
          // #end::data_structures_6[];
        }
      
        public void data_structures_7() throws Exception {
          arrayList.set(0, "first value");
          // #end::data_structures_7[];
        }
      
        public void data_structures_8() throws Exception {
          arrayList.get(0);
          // #end::data_structures_8[];
        }
      
        public void data_structures_9() throws Exception {
          arraySet.add("some_value");
          // #end::data_structures_9[];
        }
      
        public void data_structures_10() throws Exception {
          Set set = arraySet;
          // #end::data_structures_10[];
        }
      
        public void data_structures_11() throws Exception {
          arraySet.contains("value");
          // #end::data_structures_11[];
        }
      
        public void data_structures_12() throws Exception {
          arraySet.remove("some_value");
          // #end::data_structures_12[];
        }
      
        public void data_structures_13() throws Exception {
          queue.add("job123");
          // #end::data_structures_13[];
        }
      
        public void data_structures_14() throws Exception {
          Object item = queue.poll(); //=> "job123"
          // #end::data_structures_14[];
        }
      
        public void data_structures_15() throws Exception {
          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      mapGet

      Get an item from a map.

          map.get("some_key"); //=> value
          // #end::data_structures_3[];
        }
      
        public void data_structures_4() throws Exception {
          arrayList.add(1234);
          // #end::data_structures_4[];
        }
      
        public void data_structures_5() throws Exception {
          arrayList.add(0, "hello world");
          // #end::data_structures_5[];
        }
      
        public void data_structures_6() throws Exception {
          arrayList.remove(1);
          // #end::data_structures_6[];
        }
      
        public void data_structures_7() throws Exception {
          arrayList.set(0, "first value");
          // #end::data_structures_7[];
        }
      
        public void data_structures_8() throws Exception {
          arrayList.get(0);
          // #end::data_structures_8[];
        }
      
        public void data_structures_9() throws Exception {
          arraySet.add("some_value");
          // #end::data_structures_9[];
        }
      
        public void data_structures_10() throws Exception {
          Set set = arraySet;
          // #end::data_structures_10[];
        }
      
        public void data_structures_11() throws Exception {
          arraySet.contains("value");
          // #end::data_structures_11[];
        }
      
        public void data_structures_12() throws Exception {
          arraySet.remove("some_value");
          // #end::data_structures_12[];
        }
      
        public void data_structures_13() throws Exception {
          queue.add("job123");
          // #end::data_structures_13[];
        }
      
        public void data_structures_14() throws Exception {
          Object item = queue.poll(); //=> "job123"
          // #end::data_structures_14[];
        }
      
        public void data_structures_15() throws Exception {
          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      If the key is not found, a PathNotFoundException is raised.

      listAppend

      Add an item to the end of a list.

          arrayList.add(1234);
          // #end::data_structures_4[];
        }
      
        public void data_structures_5() throws Exception {
          arrayList.add(0, "hello world");
          // #end::data_structures_5[];
        }
      
        public void data_structures_6() throws Exception {
          arrayList.remove(1);
          // #end::data_structures_6[];
        }
      
        public void data_structures_7() throws Exception {
          arrayList.set(0, "first value");
          // #end::data_structures_7[];
        }
      
        public void data_structures_8() throws Exception {
          arrayList.get(0);
          // #end::data_structures_8[];
        }
      
        public void data_structures_9() throws Exception {
          arraySet.add("some_value");
          // #end::data_structures_9[];
        }
      
        public void data_structures_10() throws Exception {
          Set set = arraySet;
          // #end::data_structures_10[];
        }
      
        public void data_structures_11() throws Exception {
          arraySet.contains("value");
          // #end::data_structures_11[];
        }
      
        public void data_structures_12() throws Exception {
          arraySet.remove("some_value");
          // #end::data_structures_12[];
        }
      
        public void data_structures_13() throws Exception {
          queue.add("job123");
          // #end::data_structures_13[];
        }
      
        public void data_structures_14() throws Exception {
          Object item = queue.poll(); //=> "job123"
          // #end::data_structures_14[];
        }
      
        public void data_structures_15() throws Exception {
          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      listPrepend

      Add an item to the beginning of a list.

          arrayList.add(0, "hello world");
          // #end::data_structures_5[];
        }
      
        public void data_structures_6() throws Exception {
          arrayList.remove(1);
          // #end::data_structures_6[];
        }
      
        public void data_structures_7() throws Exception {
          arrayList.set(0, "first value");
          // #end::data_structures_7[];
        }
      
        public void data_structures_8() throws Exception {
          arrayList.get(0);
          // #end::data_structures_8[];
        }
      
        public void data_structures_9() throws Exception {
          arraySet.add("some_value");
          // #end::data_structures_9[];
        }
      
        public void data_structures_10() throws Exception {
          Set set = arraySet;
          // #end::data_structures_10[];
        }
      
        public void data_structures_11() throws Exception {
          arraySet.contains("value");
          // #end::data_structures_11[];
        }
      
        public void data_structures_12() throws Exception {
          arraySet.remove("some_value");
          // #end::data_structures_12[];
        }
      
        public void data_structures_13() throws Exception {
          queue.add("job123");
          // #end::data_structures_13[];
        }
      
        public void data_structures_14() throws Exception {
          Object item = queue.poll(); //=> "job123"
          // #end::data_structures_14[];
        }
      
        public void data_structures_15() throws Exception {
          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      listRemove

      Remove a value from a list.

          arrayList.remove(1);
          // #end::data_structures_6[];
        }
      
        public void data_structures_7() throws Exception {
          arrayList.set(0, "first value");
          // #end::data_structures_7[];
        }
      
        public void data_structures_8() throws Exception {
          arrayList.get(0);
          // #end::data_structures_8[];
        }
      
        public void data_structures_9() throws Exception {
          arraySet.add("some_value");
          // #end::data_structures_9[];
        }
      
        public void data_structures_10() throws Exception {
          Set set = arraySet;
          // #end::data_structures_10[];
        }
      
        public void data_structures_11() throws Exception {
          arraySet.contains("value");
          // #end::data_structures_11[];
        }
      
        public void data_structures_12() throws Exception {
          arraySet.remove("some_value");
          // #end::data_structures_12[];
        }
      
        public void data_structures_13() throws Exception {
          queue.add("job123");
          // #end::data_structures_13[];
        }
      
        public void data_structures_14() throws Exception {
          Object item = queue.poll(); //=> "job123"
          // #end::data_structures_14[];
        }
      
        public void data_structures_15() throws Exception {
          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      listSet

      Set an element at a specific index in the list.

          arrayList.set(0, "first value");
          // #end::data_structures_7[];
        }
      
        public void data_structures_8() throws Exception {
          arrayList.get(0);
          // #end::data_structures_8[];
        }
      
        public void data_structures_9() throws Exception {
          arraySet.add("some_value");
          // #end::data_structures_9[];
        }
      
        public void data_structures_10() throws Exception {
          Set set = arraySet;
          // #end::data_structures_10[];
        }
      
        public void data_structures_11() throws Exception {
          arraySet.contains("value");
          // #end::data_structures_11[];
        }
      
        public void data_structures_12() throws Exception {
          arraySet.remove("some_value");
          // #end::data_structures_12[];
        }
      
        public void data_structures_13() throws Exception {
          queue.add("job123");
          // #end::data_structures_13[];
        }
      
        public void data_structures_14() throws Exception {
          Object item = queue.poll(); //=> "job123"
          // #end::data_structures_14[];
        }
      
        public void data_structures_15() throws Exception {
          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      listGet

      Get an item from a list by its index.

          arrayList.get(0);
          // #end::data_structures_8[];
        }
      
        public void data_structures_9() throws Exception {
          arraySet.add("some_value");
          // #end::data_structures_9[];
        }
      
        public void data_structures_10() throws Exception {
          Set set = arraySet;
          // #end::data_structures_10[];
        }
      
        public void data_structures_11() throws Exception {
          arraySet.contains("value");
          // #end::data_structures_11[];
        }
      
        public void data_structures_12() throws Exception {
          arraySet.remove("some_value");
          // #end::data_structures_12[];
        }
      
        public void data_structures_13() throws Exception {
          queue.add("job123");
          // #end::data_structures_13[];
        }
      
        public void data_structures_14() throws Exception {
          Object item = queue.poll(); //=> "job123"
          // #end::data_structures_14[];
        }
      
        public void data_structures_15() throws Exception {
          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      If the index is out of range, a PathNotFoundException will be thrown. Note that you can get the last array element by specifying -1 as the index.

      setAdd

      Add an item to a set, if the item does not yet exist in the set.

          arraySet.add("some_value");
          // #end::data_structures_9[];
        }
      
        public void data_structures_10() throws Exception {
          Set set = arraySet;
          // #end::data_structures_10[];
        }
      
        public void data_structures_11() throws Exception {
          arraySet.contains("value");
          // #end::data_structures_11[];
        }
      
        public void data_structures_12() throws Exception {
          arraySet.remove("some_value");
          // #end::data_structures_12[];
        }
      
        public void data_structures_13() throws Exception {
          queue.add("job123");
          // #end::data_structures_13[];
        }
      
        public void data_structures_14() throws Exception {
          Object item = queue.poll(); //=> "job123"
          // #end::data_structures_14[];
        }
      
        public void data_structures_15() throws Exception {
          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      Note that a set is just a list. You can retrieve the entire set by simply using a full-document get operation:

          Set set = arraySet;
          // #end::data_structures_10[];
        }
      
        public void data_structures_11() throws Exception {
          arraySet.contains("value");
          // #end::data_structures_11[];
        }
      
        public void data_structures_12() throws Exception {
          arraySet.remove("some_value");
          // #end::data_structures_12[];
        }
      
        public void data_structures_13() throws Exception {
          queue.add("job123");
          // #end::data_structures_13[];
        }
      
        public void data_structures_14() throws Exception {
          Object item = queue.poll(); //=> "job123"
          // #end::data_structures_14[];
        }
      
        public void data_structures_15() throws Exception {
          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }
      Currently, you can only store primitive values in sets, such as strings, ints, and booleans.

      setContains

      Check if a value exists in the set.

          arraySet.contains("value");
          // #end::data_structures_11[];
        }
      
        public void data_structures_12() throws Exception {
          arraySet.remove("some_value");
          // #end::data_structures_12[];
        }
      
        public void data_structures_13() throws Exception {
          queue.add("job123");
          // #end::data_structures_13[];
        }
      
        public void data_structures_14() throws Exception {
          Object item = queue.poll(); //=> "job123"
          // #end::data_structures_14[];
        }
      
        public void data_structures_15() throws Exception {
          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      setRemove

      Remove an item from a set, if it exists. An exception is not thrown if the item does not exist. You can determine if an item existed or not by the return value. If the item did not exist beforehand, null is returned.

          arraySet.remove("some_value");
          // #end::data_structures_12[];
        }
      
        public void data_structures_13() throws Exception {
          queue.add("job123");
          // #end::data_structures_13[];
        }
      
        public void data_structures_14() throws Exception {
          Object item = queue.poll(); //=> "job123"
          // #end::data_structures_14[];
        }
      
        public void data_structures_15() throws Exception {
          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      queuePush

      Add an item to the beginning of the queue.

          queue.add("job123");
          // #end::data_structures_13[];
        }
      
        public void data_structures_14() throws Exception {
          Object item = queue.poll(); //=> "job123"
          // #end::data_structures_14[];
        }
      
        public void data_structures_15() throws Exception {
          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      Note that a queue is just a list. You can retrieve items from the middle of the queue by using listGet

      queuePop

      Remove an item from the end of the queue and return it.

          Object item = queue.poll(); //=> "job123"
          // #end::data_structures_14[];
        }
      
        public void data_structures_15() throws Exception {
          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      If the queue is empty, then null is returned.

      mapSize, listSize, setSize, queueSize

      These methods get the length of the data structure. For maps, this is the number of key-value pairs inside the map. For lists, queues, and sets, this is the number of elements in the structure.

          int len = arrayList.size(); //=> 42
          // #end::data_structures_15[];
        }
      
        public void data_structures_16() throws Exception {
          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      Note that there are only two basic types: map and list. Types such as queue and set are merely derivatives of list.

      Data Structures and Key-Value APIs

      Data structures can be accessed using key-value APIs as well. In fact, the data structure API is actually a client-side wrapper around the key-value and sub-document API. Most of the data structure APIs wrap the sub-document API directly.

      Because the data structure API is just a wrapper around the various key-value APIs, you are free to switch between them in your code.

      Collections Framework Integration

      In addition to the Bucket level methods for working with data structures, the Java SDK provides implementations of the Map, List, Set, and Queue interfaces from the Java Collections Framework. Instead of maintaining in-memory storage, these implementations are backed by JSON documents stored in Couchbase Server. The implementations are thread-safe and suitable for concurrent use. The Map, List, and Queue implementations may contain values of the following types:

      • String

      • Integer

      • Long

      • Double

      • Boolean

      • BigInteger

      • BigDecimal

      • JsonObject

      • JsonArray

      The Set implementation may contain values of all of the above types except JsonObject and JsonArray.

      CouchbaseMap

      The CouchbaseMap<V> class implements Map<String, V>. It allows null values, but does not allow null keys.

      Example usage:

          Map<String, String> favorites = new CouchbaseMap<String>("mapDocId", collection, String.class, MapOptions.mapOptions());
          favorites.put("color", "Blue");
          favorites.put("flavor", "Chocolate");
      
          System.out.println(favorites); //=> {flavor=Chocolate, color=Blue}
      
          // What does the JSON document look like?
          System.out.println(collection.get("mapDocId").contentAsObject());
          //=> {"flavor":"Chocolate","color":"Blue"}
          // #end::data_structures_16[];
        }
      
        public void data_structures_17() throws Exception {
          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      CouchbaseArrayList

      The CouchbaseArrayList<V> class implements List<V>. It allows null values.

      Example usage:

          List<String> names = new CouchbaseArrayList<String>("listDocId", collection, String.class, ArrayListOptions.arrayListOptions());
          names.add("Alice");
          names.add("Bob");
          names.add("Alice");
      
          System.out.println(names); //=> [Alice, Bob, Alice]
      
          // What does the JSON document look like?
          System.out.println(collection.get("listDocId").contentAsArray());
          //=> ["Alice","Bob","Alice"]
          // #end::data_structures_17[];
        }
      
        public void data_structures_18() throws Exception {
          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      CouchbaseArraySet

      The CouchbaseArraySet<V> class implements Set<V>. It allows null values.

      Example usage:

          Set<String> uniqueNames = new CouchbaseArraySet<String>("setDocId", collection, String.class, ArraySetOptions.arraySetOptions());
          uniqueNames.add("Alice");
          uniqueNames.add("Bob");
          uniqueNames.add("Alice");
      
          System.out.println(uniqueNames); //=> [Alice, Bob]
      
          // What does the JSON document look like?
          System.out.println(collection.get("setDocId").contentAsArray());
          //=> ["Alice","Bob"]
          // #end::data_structures_18[];
        }
      
        public void data_structures_19() throws Exception {
          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }

      CouchbaseQueue

      The CouchbaseQueue<V> class implements Queue<V>. It does not allow null values.

      Example usage:

          Queue<String> shoppingList = new CouchbaseQueue<String>("queueDocId", collection, String.class, QueueOptions.queueOptions());
          shoppingList.add("loaf of bread");
          shoppingList.add("container of milk");
          shoppingList.add("stick of butter");
      
          // What does the JSON document look like?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> ["stick of butter","container of milk","loaf of bread"]
      
          String item;
          while ((item = shoppingList.poll()) != null) {
            System.out.println(item);
            // => loaf of bread
            // => container of milk
            // => stick of butter
          }
      
          // What does the JSON document look like after draining the queue?
          System.out.println(collection.get("queueDocId").contentAsArray());
          //=> []
          // #end::data_structures_19[];
        }
      
        public static void main(String[] args) throws Exception {
          DataStructuresExample obj = new DataStructuresExample();
          obj.init();
          obj.data_structures_1();
          obj.data_structures_2();
          obj.data_structures_3();
          obj.data_structures_4();
          obj.data_structures_5();
          obj.data_structures_6();
          obj.data_structures_7();
          obj.data_structures_8();
          obj.data_structures_9();
          obj.data_structures_10();
          obj.data_structures_11();
          obj.data_structures_12();
          obj.data_structures_13();
          obj.data_structures_14();
          obj.data_structures_15();
          obj.data_structures_16();
          obj.data_structures_17();
          obj.data_structures_18();
          obj.data_structures_19();
          System.out.println("Done.");
        }
      }