11:34 am - Saturday March 25, 2017

Add key value pair to LinkedHashMap V put(K key, V value)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

                The method public V put(K key,V value ) assigns the value with the specified key in the map. Also if a map previously contains a value for the key, the old value is replaced.

Example Program


import java.util.Iterator;

import java.util.LinkedHashMap;

import java.util.Set;

public class LinkedHashMapPut 
{
	public static void main(String[] args) 
     {

		LinkedHashMap lhm = new LinkedHashMap();

		lhm.put("1", "Add");

		lhm.put("2", "Sub");

		lhm.put("3", "Mul");

		Set entrySet = lhm.entrySet();

		Iterator it = entrySet.iterator();

		System.out.println("LinkedHashMap entries : ");

		while (it.hasNext())

			System.out.println(it.next());

	}

}

Output

   LinkedHashMap entries :

        1=Add

        2=Sub

        3=Mul

BACK

 

Filed in: Java Examples

Comments are closed.