I have an HashMap object, which has with key and value pair.
It has 10 keys and values in that object. Now the question
is I want insert new key and value in middle or any where in
that list but not at the end or at the top. Is it possible
or not. If yes how can we achieve this one?

Answer Posted / manoj

package manu;

import java.util.HashMap;



public class Manu_HashMapTest
{
public static void main(String[] args)
{
HashMap<String,Integer> m=new HashMap<String,Integer>();
m.put("a",100);
m.put("b",200);
m.put("c", 300);
m.put("b", 800);//insert a new element....
System.out.println(m);
}
}

o/p->{a=100, c=300, b=800}
so Hash map does not give guarantee in order,so its not
possible to insert element in right position.

Manoj sahu,jajpur

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is object english?

581


What is difference between calling start() and run() method of thread?

555


What invokes a thread's run() method in java programming?

565


What is a string what operation can be performed out with the help of a string?

503


Can we have more than one package statement in the source file?

638






Explain java coding standards for variables ?

665


give an example for encapsulation?

580


What is Recursion Function?

637


Explain the difference between jvm and jre?

556


Why can't you declare a class as protected?

595


What is the properties class?

556


Difference between process and thread?

597


Explain the difference between abstraction and encapsulation.

535


When should I use singleton pattern?

541


What is early binding and late binding in java?

591