Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

java-hashmap

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

java-hashmap

Port Java HashMap functionality to JavaScript

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

hashmap

Port Java HashMap functionality to JavaScript. Quick and easy to pickup with the familiar syntax from Java.

Features

  • Replicated HashMap syntax from Java
  • Simple and easy to use
  • Switch between HashMaps and Objects

Documentation

Installation

Using npm:

$ npm install -g npm
$ npm install java-hashmap

In Node.js:

const HashMap = require("java-hashmap");

Creating a HashMap

The HashMap package returns a class, you can use this class to create a HashMap. For example, here is one of character colors:

const HashMap = require("hashmap");
var characterColors = new HashMap();

Interact with data

There isn't much use to a HashMap if you can't even deal with the information in it, so let's look at that.

Add data

To add data to the HashMap, use the .put() method. It takes two parameters, the key and the value.

characterColors.put("Sonic", "blue");
characterColors.put("Mario", "red");
characterColors.put("Ryu", "white");

Remove data

To remove data from the HashMap, use the .remove() method. It takes one parameter, the key.

characterColors.remove("Sonic");
characterColors.remove("Mario");
characterColors.remove("Ryu");

Clear data

To clear all the data from the HashMap, use the .clear() method.

characterColors.clear();

Reading data

The ability to modify data is no good if you can't even read it. So, there are a lot of methods with HashMaps for reading data.

Getting values by keys

To get a value by it's associated key, use the .get() method. It takes one parameter, the key.

characterColors.get("Sonic");
characterColors.get("Mario");
characterColors.get("Ryu");

Getting all the data (in the form of Arrays)

To get all the data in the form of two Arrays, use the .get() method without supplying any parameters.

characterColors.get();

Getting all the keys

To get all the keys, use the .keySet() method.

characterColors.keySet();

Getting all the values

To get all the values, use the .values() method.

characterColors.values();

Getting the size of the HashMap

To get all the size of the HashMap, use the .size() method.

characterColors.size();

Generate HashMap from Object/Array

Sometimes it's useful to generate a HashMap from an Object or an Array, to do so use the .generate() method.

const characterColors = new HashMap();

//With one Object
characterColors.generate({
    Sonic: "blue",
    Mario: "red",
    Ryu: "white"
});
/*["Sonic", "Mario", "Ryu"]
["blue", "red", "white"]*/

//With two Arrays
characterColors.generate(
    ["Sonic", "Mario", "Ryu"],
    ["blue", "red", "white"]);
/*["Sonic", "Mario", "Ryu"]
["blue", "red", "white"]*/

//With one Array
characterColors.generate(["Sonic", "Mario", "Ryu"]);
/*[0, 1, 2], ["Sonic", "Mario", "Ryu"]*/

Keywords

FAQs

Package last updated on 09 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc