Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

retrieve kv pairs using hashmap

Ads

 
 

Share on Google+Share on Google+

sahil girdhar
retrieve kv pairs using hashmap
1 Answer(s)      5 years and 5 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?

Ads
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 + ", ");
            }
        }
    }

}

Ads









Related Tutorials/Questions & Answers:
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
HashMap
HashMap  How to work hashmap and hashset internally
Advertisements
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
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
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
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
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
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
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
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
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
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 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
<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
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
Java hashmap, hashtable
Java hashmap, hashtable  When are you using hashmap and hashtable
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
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
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
HashMap - Struts
HashMap  Can you please get me an example code for using HashMap in Jsp and what for what purpose it is used
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.
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
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
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
How to get Keys and Values from HashMap in Java?
How to get Keys and Values from HashMap in Java? Example program of iterating through HashMap In this tutorial I will explain you how you can iterate through HashMap using the entrySet() method of HashMap class. You will be able
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