Home Answers Viewqa Java-Beginners Java Map Example

 
 


Naulej kumar
Java Map Example
1 Answer(s)      11 months ago
Posted in : Java Beginners

How we can use Map in java collection?

View Answers

June 20, 2012 at 12:16 PM


The Map interface maps unique keys to value means it associate value to unique keys.

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapExample {
    public static void main(String[] args) {

        Map mp = new HashMap();
        mp.put(new Integer(2), "Two");
        mp.put(new Integer(1), "One");
        mp.put(new Integer(3), "Three");
        mp.put(new Integer(4), "Four");

        Set st = mp.entrySet();

        Iterator it = st.iterator();

        while (it.hasNext()) {

            Map.Entry m = (Map.Entry) it.next();

            int key = (Integer) m.getKey();

            String value = (String) m.getValue();
            System.out.println("Key :" + key + "  Value :" + value);

        }
    }
}

Output:

Key :1  Value :One
Key :2  Value :Two
Key :3  Value :Three
Key :4  Value :Four

Description:- The above example demonstrates you the Map interface. Since Map is an interface, you need to instantiate a concrete implementation of the interface in order to use it. Here Map is implemented by its subclass HashMap. Using the put method, we have added elements to key and value pair. Now to display the key and values, we have called getKey() and getValue() methods that are defined by Map.Entry.









Related Pages:
Map
Map  If I have an object implementing the Map interface in Java and I... way of going through the map either iterator or for each loop or for loop   Here is an example of HashMap. import java.util.*; public class
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... Description:- The above example demonstrates you the Map interface. Since Map
Map
;Please visit the following links: HashTable Example ArrayList Example HashMAp Example
Java Map iterator with example
() method to get the data in Set object form. Java Map Iterator with Example... Java Map Iterator is an interface. It keeps the data in the key and value form. It is implemented by HashMap, Tree Map. Map has no iterator method. So
Java Map Example
the key and values. Map.Entry defines both of these methods. Java Map Example...Map Interface adds keys to values. Every key in the Map Interface should be unique. It is part of java.util package. Each element in a map has a key
Java Map Iterate
Map is an Interface in the Collection Framework. Map is implemented by its two sub classes HashMap Treemap Map has no iterator method. So use the entrySet() method.It returns the data as Set Example of Java Map
Site map - C Tutorials
default values | C Array Declaration | C Array copy example Java Tutorial... | Site Map | Business Software Services India Tutorial Section   C Tutorials  | Java Tutorials | PHP Tutorials  | Linux
Site map Index
SECTION     Java Tutorials | Java Code example | Java... | Site Map | Business Software Services India Web Services Tutorial ... Tutorial  | Java Script Tutorial | PHP Tutorial | Java Servlet
Site Map
Java Code example Java Programming Java Beginners... Site Map We have organized our site map for easy access. You can browser though Site Map to reach the tutorials and information pages. We
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... will help me to do so.....?????? i am using java swings
Tree Map Example
Tree Map Example     ...(String[] args) { System.out.println("Tree Map Example!\n"); TreeMap <... the tree map contain: " + tMap.values()); } } Download this example
Introduction to Map and SortedMap Interface
C:\nisha>java MapDemo Keys of tree map: [0, 1, 2, 3, 4... Introduction to Map and SortedMap Interface       Map Interface: A Map
Map java Object to database.
Map java Object to database.  How do you map Java Objects with Database tables
JavaScript google map API example.
JavaScript google map API example.  How to Use Google Maps API in JavaScript?   Google Maps- A map is a way of representation of your route...;/html> Description: - This example loads the google map with defined
parse map in java
parse map in java  What is a Parser? Can you give the source code to parse map in Java
hash map
int getI2(){ return i2; } } class Example{ public static void main...=2; HashMap<Integer,Test> map=new HashMap<Integer,Test>
Spring Map Example
Spring Map Example In this example you will see how bean is prepared for injecting Map collection type key and its values. MapBean.java...: Satya = 101 Rohit = 102 Aniket = 103 Download this example code
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
Navigable Map Example
C:\vinod\collection>java NavigableMapExample Navigable Map Example... Navigable Map Example     ... have a look at the example. Description of program: The following program helps
Map Iteration
Java: Map Iteration No direct iteration over Maps -- Get Set of keys...()) can be obtained from the Map, and one can iterate over that. Order of map elements in iteration The order of the elements obtained from a Map depends
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
Java map building - Development process
Java map building  Hello All I want to build a map for a road... to proceed further i need to build a map using these coodinates which i am unable to think of how to do it. I can only use java swing or 2d for this purpose. Any
Map Java Objects with Database tables
Map Java Objects with Database tables  How to map Java Objects with Database tables?   First write Java domain objects ie. beans with setter and getter methods. Then map java class to table and database columns to Java
Example to show Hash map exception in java
Example to show Hash map exception in java       The implementation of map interface is based...-value pairs Understand with Example Hash map in java is same as the Hash table
How to use Map in velocity
How to use Map in velocity       This Example shows you how to use map in velocity. The method...;map.put("libno", 1001);   list.add(map);   map 
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
Java: Map Iteration
Java: Map Iteration No direct iteration over Maps -- Get Set of keys...()) can be obtained from the Map, and one can iterate over that. Order of map elements in iteration The order of the elements obtained from a Map depends
java code to compare two hash map objects
java code to compare two hash map objects  java code to compare two hash map objects
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
Using Arraylist or Hash Map - Java Interview Questions
Using Arraylist or Hash Map  what could b the pros and cons changing between Hash Map to Array List
Spring Map Factory, Spring Map Configuration
Spring Map Factory Ths MapFactoryBean is a simple factory for shared Map instance. The map element is defined in the xml bean definitions. The setSourceMap method set the source Map which is written in xml map element
Adding an Input Map to a Component
Adding an Input Map to a Component   ... map. Input map is used to perform actions according to the key strokes...* package. This class is used to create an input map. It performs the work
Spring Map Property
Spring Map Property The Spring Framework has bean support for the Collections. It provide list, set, map and props elements. Here in this tutorial you will see about the map elements which is used to set values inside the map
google map with jsf - Java Server Faces Questions
google map with jsf  hi, i am using jsf with googlemap.i load the script file with googlemap .its working fine.how can i load the database values(latlong) to googlemap from jsf bean values.i want to show mutiple markers
Wiring Map Collections
; defines a member of the Map. Lets take an example to demonstrate how map...Wiring map collections The <map> element is used to store values in key... and authorsInfo is of Map type. import java.util.*; public class Article
How do you map Java Objects with Database tables?
How do you map Java Objects with Database tables?  Hi, How do you map Java Objects with Database tables? thanks
Site Map - All java tutorials
Site Map - All java tutorials In this section of sitemap we have listed all the important sections of java tutorials. Select the topics you want... Java AWT Package Examples Swing Example Java util
Generate area for map from backing bean - Java Server Faces Questions
Generate area for map from backing bean  I need to populate the map in my page, and the coordinates should come from the backing bean.. How could I do
Java HashMap example.
Java HashMap example. The HashMap is a class in java. It stores values in name values pair. You can store null value of key and values.   Here... of map. Code:  HashMapExample .java package net.roseindia.java
Map words to line number in text file and show occurence
Map words to line number in text file and show occurence  hi i want to Map words to line number in text file and show occurrence of word in java coding
Wiring Map Collections Using References
to provide values as references to other beans. Lets take an example... because of uniqueness feature of set type collection. For example <bean id
read from file and store using hash map
read from file and store using hash map  I was stuck with a java project where I have to read a file with two different concepts and store them differently in hashmap. My data file would be something like Adults: Name, xyz
Map interface
Map interface  What is the Map interface
java run time textfield and use with map - Java Beginners
java run time textfield and use with map  i want to program which read data from file and store in map and display in different textfields which are generated at run time like a text file store information class a1
Hash Map
Hash Map  how to add the hash map objects in the list and iterate the objects
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
OOPS Concept Abstraction with example - Java Beginners
). For example, the Java Collections Framework defines the abstraction called...OOPS Concept Abstraction with example  I am new to java. In java... it with one example  Hi Friend, The process of abstraction in Java is used
Java: Maps
Java: Maps Key-Value pairs Key-value pairs are stored in maps. Map interfaces Map implemented by HashMap and TreeMap SortedMap implemented by TreeMap.... Implementing classes A number of classes implement the Map interface, including

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.