Lists, HashMaps and HashSets in Visual Bukkit explained!

Visual Bukkit has standard blocks for common collections like lists, hashmaps, and hashsets. These are clearly explained below!

List

A list is an ordered collection of elements. This means you can use the index to retrieve a specific element from the list. Unlike sets, a list can contain duplicates.

In Visual Bukkit, you can create a list using the “List” block. There, you can create and add items that define the list.

Common methods on a list are:

MethodDescription
add()Adds an element to the end of the list
get()Returns the element at the specified position
set()Replaces the element at the specified position
remove()Removes the element at the specified position
size()Returns the number of elements in the list

You can find all the List methods and their explanation here.

In Visual Bukkit these methods could be found in the List class:

Immutable List

Immutable means unchangeable. You cannot add or remove items from an immutable list after it has been created. Because its size cannot change, it can be more efficient than a regular list.

HashMap

A HashMap stores a unique key and value. Each key is unique and is used to retrieve its associated value.

Common methods are:

MethodDescription
put(key, value)Adds or replaces a key–value pair
get(key)Retrieves the value associated with a key
remove(key)Removes a key and its value
size()Returns the number of keys in the HashMap
values(), keySet()Returns a collection of all values or keys

HashSet

A HashSet is a collection n which all elements are unique. Unlike a list, a HashSet does not maintain any order and does not use indexes.

Common methods are:

MethodDescription
add()Add an element
contains(value)Does a certain element exist?
remove(value)Remove a value
size()The size of the HashSet

And other types?

Other collection types are not available by default, though you can easily create them with the new Object block.


Home » Lists, HashMaps and HashSets in Visual Bukkit explained!

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *