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
Write a program to calculate factorial in java?
What is the purpose of final keyword and when to use it?
How to solve the problem of generating the unique hash keys with hash function?
Explain about version control?
Can we sort set in java?
Explain 5 features introduced in jdk 1.7?
How do you use equal in java?
What do you know about java?
Can a lock be acquired on a class in java programming?
If a class is declared without any access modifiers, where can the class be accessed?
If I don't provide any arguments on the command line, then what will the value stored in the string array passed into the main() method, empty or null?
What is charat ()?
What is hotjava?
What are thread safe functions?
Name and explain the types of ways which are used to pass arguments in any function in java.