Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Thadeuse
Map
1 Answer(s)      2 years and 2 months ago
Posted in : Java Beginners


If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map either iterator or for each loop or for loop


Advertisement
View Answers

October 5, 2012 at 4:01 PM


Here is an example of HashMap.

import java.util.*;

public class HashMapExample{

  public static void main(String[] args){
    HashMap hm = new HashMap();
    hm.put(1,"A");
    hm.put(2,"B");
    hm.put(1,"C");
    hm.put(3,"D");
    hm.put(4,"E");

    Set set = hm.entrySet();

    Iterator i = set.iterator();

    while(i.hasNext()){
      Map.Entry me = (Map.Entry)i.next();
      System.out.println(me.getKey() + " : " + me.getValue() );
    }
  }
}


Related Tutorials/Questions & Answers:
map
map  using map, i want display message based on id selected [both are strings]   i do no   Hi Friend, Try the following code...) { Map map=new HashMap(); map.put("Message1","Hello
Map
Map  If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map either iterator or for each loop or for loop
Advertisements
Map interface
Map interface  What is the Map interface
Hash Map
Hash Map  how to add the hash map objects in the list and iterate the objects
Interactive map
Interactive map  hi........ i require map to be zoom in and enlarge the area and show its detail. Can anyone tel me how can this be done using java swings .... plz help
Map code
Map code  hi................ I have map of navi mumbai, where i want to see the location vashi, nerul, turbhe.... means want to zoom into this area and then again zoom in and see nerul location more properly or other location
Map
hash map
hash map  write a program in hash map , that shows the value in asending order. but not key value. ex: key value ==== ===== k5 ashutosh k1 babita k7 debasis k2 vikas plz help me
hash map
=2; HashMap<Integer,Test> map=new HashMap<Integer,Test>
parse map in java
parse map in java  What is a Parser? Can you give the source code to parse map in Java
solution of k map in c
solution of k map in c  write a program in c to solve k-map with digital circuit
Map java Object to database.
Map java Object to database.  How do you map Java Objects with Database tables
Iterate Tag used with a Map.
Iterate Tag used with a Map.  How Iterate Tag used with a Map
about google map
about google map  how to add google map in website
about google map
about google map  how to add google map in website
add google map javascript
add google map javascript  How can i add google map using javascript in my web page?   Search for the " Google Maps Javascript API" it will allow you to embed the Google Map into your web Page
map on web page
map on web page   i want to insert an area map in my web page how can i do it ? please answer me soon. Its urgent
Stoting file name in Map
Stoting file name in Map  how to store id and file name in map
Google Map Integration - Ajax
Google Map Integration  Hi All, I am working on a vehicle tracking system project. I have to read data from sql server database and map the vehicle position in google map. I need to use ajax as the data is updated in every
Store ResultSt Data in a Map
Store ResultSt Data in a Map  i want to store data in a hash Map .Please solve my problem as soon as possible
ApplicationDevelopment Using Google Map
ApplicationDevelopment Using Google Map  I want application using google map please guide me how can i develop
Java Map Example
Java Map Example  How we can use Map in java collection?   The Map interface maps unique keys to value means it associate value to unique...(String[] args) { Map mp = new HashMap(); mp.put(new Integer(2
How to hold data in map
How to hold data in map  Holding data in map: i have user1 and he has account1,account2,accoutn3 like that user2,user3 will have accounts. now how to hold users and their accounts in hashmap
J2me Map load error
J2me Map load error  Hi , i am making a POC to load google map in my mobile,now i m getting the address of location by its lattitude and longitude in web page , but thing is i wana to store in my net beans emulator , its showing
java code for PartialSearch using Map????
java code for PartialSearch using Map????  java code for Partial Search using Map
Java tree map trouble
Java tree map trouble  This is a project for a class, and I am totally stuck! I've created a tree map using an input text file. I split the lines into fields so that I could work with 2 elements from the file. It appears
alias_to_entity_map
In this section, you will learn about attribute 'alias_to_entity_map' of method 'setResultTransformer' which converts each row of result into a Map
Site map - C Tutorials
Index  | About-us | Contact Us | Advertisement | Ask Questions | Site Map | Business Software Services India Tutorial Section   C Tutorials  | Java Tutorials | PHP Tutorials  | Linux
Java Map
Java Map         In Java, a Map is a kind of generalized array. It provides a more general way of storing elements. It is an object that maps keys to values. Map
Using of [] operator of EL with the Map
Using [ ] operator of EL with the Map   ... Map key or a bean property name as well as the access to arrays and Lists. Map stores the values in the form of a key- value pair. Map can't have a duplicate
Reading Text file and storing in map
Reading Text file and storing in map  Hi I have multiple text files. I want to read thoses files and store those records in map. Map will be of "LinkedHashMap<String, Map<String, String>>" type. Please let me know
Advertisements
 

 

 

DMCA.com