Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Write a program to calculate factorial in java?

968


What is the purpose of final keyword and when to use it?

959


How to solve the problem of generating the unique hash keys with hash function?

1871


Explain about version control?

994


Can we sort set in java?

918


Explain 5 features introduced in jdk 1.7?

978


How do you use equal in java?

1015


What do you know about java?

904


Can a lock be acquired on a class in java programming?

937


If a class is declared without any access modifiers, where can the class be accessed?

1024


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?

1219


What is charat ()?

897


What is hotjava?

967


What are thread safe functions?

908


Name and explain the types of ways which are used to pass arguments in any function in java.

1029