Checkout for Promo Codes

Program: Basic LinkedHashMap Operations.


Here you can find example code for basic LinkedHashMap operation. It shows how to create object for LinkedHashMap, adding elements, getting size, checking empty or not, remove, etc.

package com.java2novice.linkedhashmap;

import java.util.LinkedHashMap;

public class BasicLinkedHashMap {

	public static void main(String a[]){
		LinkedHashMap<String, String> lhm = new LinkedHashMap<String, String>();
		lhm.put("one", "This is first element");
		lhm.put("two", "This is second element");
		lhm.put("four", "this element inserted at 3rd position");
		System.out.println("Getting value for key 'one': "+lhm.get("one"));
		System.out.println("Size of the map: "+lhm.size());
		System.out.println("Is map empty? "+lhm.isEmpty());
		System.out.println("Contains key 'two'? "+lhm.containsKey("two"));
		System.out.println("Contains value 'This is first element'? "
							+lhm.containsValue("This is first element"));
		System.out.println("delete element 'one': "+lhm.remove("one"));

{one=This is first element, two=This is second element, four=this element inserted at 3rd position}
Getting value for key 'one': This is first element
Size of the map: 3
Is map empty? false
Contains key 'two'? true
Contains value 'This is first element'? true
delete element 'one': This is first element
{two=This is second element, four=this element inserted at 3rd position}
Next Program >>

List Of All LinkedHashMap Sample Programs:

  1. LinkedHashMap basic operations
  2. How to iterate through LinkedHashMap?
  3. How to check whether the value exists or not in a LinkedHashMap?
  4. How to delete all entries from LinkedHashMap object?
  5. How to eliminate duplicate user defined objects as a key from LinkedHashMap?
  6. How to find user defined objects as a key from LinkedHashMap?
  7. How to delete user defined objects as a key from LinkedHashMap?
Knowledge Centre
Purpose of garbage collection
The garbage collection process is to identify the objects which are no longer referenced or needed by a program so that their resources can be reclaimed and reused. These identified objects will be discarded.
Famous Quotations
The pessimist complains about the wind; the optimist expects it to change; the realist adjusts the sails.
-- William Arthur Ward

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2020 by Nataraja Gootooru. All Rights Reserved.