Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java add to map

HashMap<String, String> map = new HashMap<>();
map.put("key", "value");
Comment

Add Elements in java map

// Java program to demonstrate
// the working of Map interface

import java.util.*;
class Main {
	public static void main(String args[])
	{
		// Default Initialization of a
		// Map
		Map<Integer, String> hashmap1 = new HashMap<>();

		// Initialization of a Map
		// using Generics
		Map<Integer, String> hashmap2= new HashMap<Integer, String>();

		// Inserting the Elements
		hashmap1.put(1, "Apple");
		hashmap1.put(2, "Banana");
		hashmap1.put(3, "Mango");

		hashmap2.put(new Integer(1), "Mango");
		hashmap2.put(new Integer(2), "Apple");
		hashmap2.put(new Integer(3), "Banana");

		System.out.println(hashmap1 +"
");
		System.out.println(hashmap2);
	}
}
Comment

PREVIOUS NEXT
Code Example
Java :: printing 2d array in java 
Java :: fibonacci number in java 
Java :: build tools java 
Java :: concat result of List to one text java 
Java :: reverse a integer in java 
Java :: dark mode app android studio 
Java :: setting scale to big decimal java 
Java :: java while loop example 
Java :: timestamp to date java 
Java :: java comments 
Java :: java break multiple loops 
Java :: uuid from any string java 
Java :: Add delay to code in Android 
Java :: remove first and last character from string in java 
Java :: how to add element to end of array java 
Java :: java check if file exists 
Java :: string to stream java 
Java :: retrofit android 
Java :: java mongodb find with multiple conditions 
Java :: java hash password 
Java :: java timer 
Java :: param query spring boot 
Java :: how to output sum of even numbers in java between two user values 
Java :: java swing dialog box 
Java :: java protected private public 
Java :: is palindrome java 
Java :: java constructor overloading 
Java :: java standard exception 
Java :: flink prometheus alert on failed jobs 
Java :: how to calculate angle difference 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =