8:34 pm - Thursday April 27, 2017

Remove key value pair from LinkedHashMap V remove(Object key)

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 remove(Object key) removes the particular key from the linkedhashMap,if the key is present. After performing the remove() function it displays the remaining keys in the map.

Example Program


import java.util.LinkedHashMap;

public class LinkedHashMapRemove 

{

	public static void main(String args[])

	{

		LinkedHashMap lhm = new LinkedHashMap();

		lhm.put(1, "Add");

		lhm.put(2, "Sub");

		lhm.put(3, "Mul");

		lhm.put(4, "Div");

		System.out.println("The Map:" + lhm);

		Object value = lhm.remove(1);

		System.out.println("The map after removing '1':" + lhm);

		System.out.println("The map contains:" + lhm);

	}

}


Output

   The Map:{1=Add, 2=Sub, 3=Mul, 4=Div}

   The map after removing ‘1’:{2=Sub, 3=Mul, 4=Div}

   The map contains:{2=Sub, 3=Mul, 4=Div}

BACK

Filed in: Java Examples

Comments are closed.