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

Which class represents the socket that both the client and server use to communicate with each other?

565


What is a substitution variable?

557


What is bytecode in java ?

602


Difference between operator overloading and function overloading

604


What is the differences between c++ and java? Explain

582






Which is the best sorting technique in java?

515


Write a program to print all permutations of string?

673


What are the three types of design patterns?

507


What is memory leak and how does java handle it?

515


What is the transient keyword?

625


What does \ mean in regex?

619


Is an integer an object?

513


Tell me how many ways are there to initialise an integer with a constant.

636


What is the symbol for line break?

604


Is binary a low level language?

493