Home Answers Viewqa Java-Beginners retrieve kv pairs using hashmap

 
 


sahil girdhar
retrieve kv pairs using hashmap
1 Answer(s)      a year and 4 months ago
Posted in : Java Beginners

i want to retrieve k,v-pairs from a hashmap. the entrys are like this:

a = 3,4 b = 5,6

and so on. i need combinations of these values.

a=3, b=5. a=3, b=6. a=4, b=5. a=4, b=6.

I don't know how many keys and how many entrys the values have. with entryset i can get the values but not combinations. it looks like recursion but how?

View Answers

January 26, 2012 at 5:58 PM


import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;


public class R2T2Generator {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        R2T2Generator r2t2generator=new R2T2Generator();
        Map<String,String[]>map=new TreeMap<String,String[]>();
        map.put("ProductSet",new String[]{"IA","EA"});
        map.put("role",new String[]{"Internal","External"});
        map.put("mode",new String[]{"D"});
        r2t2generator.mapPermute(map, "");
    }
    public void mapPermute(Map<String, String[]> map, String currentPermutation) {
        String key = map.keySet().iterator().next(); // get the topmost key

        // base case
        if (map.size() == 1) {          
            for (String value : map.get(key)) {
                System.out.println(currentPermutation + key + "=" + value);
            }
        } else {
            // recursive case
            Map<String, String[]> subMap = new TreeMap<String, String[]>(map);

            for (String value : subMap.remove(key)) {
                mapPermute(subMap, currentPermutation + key + "=" + value + ", ");
            }
        }
    }

}









Related Pages:
retrieve kv pairs using hashmap
retrieve kv pairs using hashmap  i want to retrieve k,v-pairs from a hashmap. the entrys are like this: a = 3,4 b = 5,6 and so on. i need combinations of these values. a=3, b=5. a=3, b=6. a=4, b=5. a=4, b=6. I don't know
Java HashMap - Java Tutorials
to retrieve value at a later date. Some of the key points are : Using a key and a value, you can store the value in Map object. You can retrieve it later by using it's key. When no element exists in the invoking Map, many methods
Query regarding hashmap
Query regarding hashmap  I want to store some names and ids in hashmap in session, then retrieve it on next page and iterate through ids to run a query using ids one at a time
HashMap in Java
HashMap class is used to implement Map interface. The value of HashMap is stored using get() and put(). HashMap provides key-value access to data. HashMap is almost equal to HashTable, the only difference is that HashMap allows null
Collection : HashMap Example
Collection : HashMap Example This tutorial will help you in understanding of HashMap concept. HashMap : The java.util.HashMap class implements Map... values that is each value has unique key through which we can retrieve
HashMap - Struts
HashMap  Can you please get me an example code for using HashMap in Jsp and what for what purpose it is used
how to load a table of data from oracle, to a jsp page using hashmap.
how to load a table of data from oracle, to a jsp page using hashmap. ... to this data i have to retrieve their details from the database(oracle). I have to use the hashmap.How can i convert a result set object to hashmap object
Java hashmap, hashtable
Java hashmap, hashtable  When are you using hashmap and hashtable
Example for when to use ArrayList and when to use HashMap - Java Interview Questions
to retrieve the objects more often then HashMap is preferable.This is the basic... example for this "once objects stored using arraylist ow to retrieve that using... u have replied this answer for when to use arraylist and hashmap " When your
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. Map.Entry which describes access methods to the key-value pairs. Implementing
hashmap
hashmap  write a program that shows the use of Hashmap class
HASHMAP
HASHMAP  HI CAN WE ADD PRIMITIVE DATA TYPE IN HASHMAP IN JAVA 1.5 VERSION . THANKS KALINS NAIK   Java HashMap Example
iterating hashmap values in struts2
iterating hashmap values in struts2  hi, i am not getting how to display this map values in jsp page using struts2 public class ViewOperation2 { public Map<String,Object> viewCustDetails(){ Map<String
Hashmap
Hashmap  Hi i want to date and day in hashmap , 1 want to display according to day with date, how to write aprograme
Hashmap
args[]){ HashMap hm=new HashMap(); hm.put(new Integer(2), "Two"); hm.put...*; public class HashTable { public static void main(String args[]){ HashMap hm=new HashMap(); hm.put(new Integer(2), "Two"); hm.put(new Integer(1
HashMap
HashMap  How can you get a HashMap to Display Text onto a Text Field that is defined and Set up to JPanel on a different Class static class public static Map <String, ActionListener> listener = new HashMap <String
Java Hashmap Iterator
Java HashMap Iterator is a collection class. It implements the Map interface. It keeps the data in the key and value form. Java HashMap has no iterator.... Set's all elements can be traversed by the Iterator. Java Hashmap Iterator
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. Map.Entry which describes access methods to the key-value pairs
tO FIND UNIQUE WORDS IN A FILE USING HASHMAP
tO FIND UNIQUE WORDS IN A FILE USING HASHMAP  import java.util....() { // create a HashMap to store unique combination of words... HashMap map = new HashMap(); int cc=0; // populate the map
Implementing a SoftReference based HashMap - Java Tutorial
objects from the HashMap by looking them up using the SoftValue.key data member...Implementing a SoftReference based HashMap 2001-03-28 The Java Specialists' Newsletter [Issue 015] - Implementing a SoftReference based HashMap Author
Saving and Retrieving The Preferences
are the constant  key/value pairs. In the pairs of key and value the key... will learn about the way to retrieves the user preference node using the same... we stored the value "roseindia" and retrieve it via user's
Any Link Between ArrayList and HashMap - Java Interview Questions
of objects while HashMap is a collection of key and value pairs while 2... interview questions which relates ArrayList and Hashmap. I mean how to link ArrayList and HashMap. Thanks Prakash  Hi Friend, Similarities: 1
Unable to bind to a hashmap from jsp using spring tags - Spring
Unable to bind to a hashmap from jsp using spring tags  Hi, I am unable to bind a hashmap from my jsp page. Here is what i want to do: I have... to bind with the hashmap dynamically.) On submission of the form i need the label
Image retrieve
Image retrieve  HI.. store image path/data Java Coding. ... It's supposed to take the image, store it in a directory as well as pass the image path to mysql database... Now I want to retrieve the data from directory using path
Problem while using a HashMap for writing text ina RTF file. - Framework
Problem while using a HashMap for writing text ina RTF file.  Hi, I am trying to generate a RTF file using iText.jar, wherein I am taking...() { objHashMap = new HashMap(); objHashMap.put("Key1","DBMCCSSSSSSSSSSSSSSSSSSSSSSSS
Retrieve data using Criteria api
Retrieve data using Criteria api  import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Query; import org.hibernate.Criteria; import org.hibernate.criterion.Restrictions; import
when to use ArrayList and when to use HashMap - Java Interview Questions
. But if you need to retrieve the objects more often then HashMap is preferable.This is the basic diff. Aray-List is fast for storing and hashmap is fast for retrieving... ArrayList and when to use HashMap in web applications . Thanks Prakash  When
Insert or retrieve image into oracle 10g by using java
Insert or retrieve image into oracle 10g by using java   How can i insert or retrieve image into oracle10g using java plz i need it urgently,need guidance to do this plz
How to Retrieve Data from Facebook Using PHP
How to Retrieve Data from Facebook Using PHP  is this link has right content regards that?? http://techpdf.co.cc/blog/how-to-retrieve-data-from-facebook-using-php
How to Retrieve Data from Facebook Using PHP
How to Retrieve Data from Facebook Using PHP  is this link has right content regards that?? http://techpdf.co.cc/blog/how-to-retrieve-data-from-facebook-using-php
Program to count the number of unique words in a file using HashMap
Program to count the number of unique words in a file using HashMap  import java.io.File; import java.io.FileNotFoundException; import java.util.*; public class CountUniqueWords { public static void main(String args
image retrieve - Java Beginners
Image Retrieve  How to retrieve the image from mysql field using java
retrieve data from database using jsf
retrieve data from database using jsf  Hello I want an example of source code to retrieve data from database i have a database (oracle) name as db1...),, name ,and city I want after enter value in textbox according idauthor i retrieve
HOW TO SAVE XML INTO MYSQL AND RETRIEVE IT USING JAVA
HOW TO SAVE XML INTO MYSQL AND RETRIEVE IT USING JAVA  H ello, i have an xml code, i need to save it into mysql 5.5 server database using java. i also want to be able to retrieve it as well. please note that i want it saved
Retrieve values from database using views
Retrieve values from database using views  hi......... I have a huge... the columns which are required. As my front end is java swings i want to retrieve data... giving me error . So can u plz help??????? Can u tell me how to retrieve data
<img src=""> using retrieve image from database using jsp
using retrieve image from database using jsp  how to <img src="" > tag using retrieve image from database and display in jsp
Retrieve data from xml using servlets
Retrieve data from xml using servlets  Hi plz send me the code for retrieving the data from xml File using Servlets.   Hi, Do you want.... Thanks Deepak   Hi, Here is one tutorial: Create XML File using Servlet
retrieve in xml file in struts2
retrieve in xml file in struts2  i am using struts2 and trying... properties file using ajax. i now put the values from properties file to map inside the bean class and based on the number entered i retrieve the name. now how
Sql row retrieve - SQL
retrieve rows from a table by specifying the row numbers such as row no.5 to 10...; Sir What are the sql statements so that I can retrieve rows from a table... that, without using where clause. thanks Pabitra kr debanth. Guwahati
Retrieve the String using expression
Retrieve the String using expression       This Example describes the way to retrieve the String using expression.For this we are going to make program named NotLookahead.java.
Struts insert & retrieve
Struts insert & retrieve  Give a struts prg to insert and retrieve data from mysql db using the struts tags(no jsp scriplets and expressions) following mvc arch. i.e. model containing db connectivity, form containing get &
Access the User's node and Retrieve the Preference Information in Class
; // Retrieve method of Using a Class   Preferences prefs.../lang/String");      //  Retrieve method of Using...; // User preference nodes      // Retrieve method of Using
Retrieve data from databse using where in JSP
Retrieve data from databse using where in JSP  Hi, can somebody help me? I have a jsp page. in that i want to get data from the database where username is matched. i tried it. but can't get the output. here is the code. please
retrieve multiple attribute values
retrieve multiple attribute values  Hello All Am a beginner. Would... like is to retrieve both the attribute values of process:Output during execution time, store them so that it can be retrieved for later use using Java. Thanks
retrieve multiple attribute values
retrieve multiple attribute values  Hello All Am a beginner. Would... like is to retrieve both the attribute values of process:Output during execution time, store them so that it can be retrieved for later use using Java. Thanks
retrieve multiple attribute values
XML retrieve multiple attribute values  Hello All Am a beginner...; What I would like is to retrieve both the attribute values of process... using Java. Thanks in advance
How to retrieve the file status?
How to retrieve the file status?  Hi all, I did a project which... dept if the file is with customs. Please provide me a code using JSP on how to retrieve the result..... I don't want to use Ajax. Thanks a lot
how to store,retrieve,modify the data
how to store,retrieve,modify the data  hello sir ,how to store,retrieve,modify the data using the swing please help me
how to store and retrieve images int and from the database using php
how to store and retrieve images int and from the database using php  please anyone can help me in storing the images and retrieve it back from the Mysql database using php
how to store and retrieve image using struts2 and hibernate integration
how to store and retrieve image using struts2 and hibernate integration  how to store and retrieve image using struts2 and hibernate integration? plz help !! thanks in advance

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.