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
Does chrome use java?
What are streams?
what is the difference between future and callable interface in java?
What are different access specifiers in java? Explain
What is difference between length and length() method in java ?
Can arraylist hold different types java?
What is native method in java?
Which sorting is best in java?
Does set allows null in java?
What is the console in java?
Why is java called java?
What is the difference between an inner class and a sub-class?
How does arraylist size increase in java?
What do you mean by garbage collection used in java?
Can java run on google chrome?