Skip to content

HashMap

Larrox edited this page Aug 29, 2025 · 2 revisions

The HashMapUtil is a utility class in LarroxUtilsAPI that makes it easier to create and work with Map objects in Java.
It provides quick methods for creating empty maps, maps with predefined entries, and even a builder-style approach for more complex usage.


Note

Don’t forget to import the HashMapUtil before using it!

import dev.larrox.HashMapUtil;

🚀 Features

  • Create an empty map with a single method call.
  • Create a map with multiple entries using varargs.
  • Quickly create a map with a single key-value pair.
  • Use a builder pattern for more advanced cases.

🛠️ Examples

Empty Map

Map<String, Integer> empty = HashMapUtil.create();

Map with Entries (varargs)

Map<String, String> map1 = HashMapUtil.of(
    "Name", "Steve",
    "World", "Overworld"
);

Map with a Single Key-Value Pair

Map<Integer, String> map2 = HashMapUtil.of(1, "One");

Builder Style

Map<String, Integer> map3 = HashMapUtil.<String, Integer>builder()
    .put("Apple", 5)
    .put("Banana", 10)
    .build();

✅ Best Practices

  • Use of() when you need a quick map with a few entries.
  • Use builder() for more readable and scalable maps when adding multiple pairs.
  • Prefer create() if you want an empty map to fill later.

Clone this wiki locally