How to print values in a HashMap

Hi
I am new to Java
I am using a HashMap where key is a String and the Value is again a HashMap..
Firstly can I use it this way ...If not could you please suggest an alternative...
If I can use it ...
I am unable to print the values in the HashMap..
Here "map" is a HasMap I am using..
and I used
map.put("name",secondMap);
My code is
public void printMap(Map map)
          Set keys = map.keySet();
          Iterator keyIter = keys.iterator();
          while (keyIter.hasNext())
               Object key = keyIter.next();
               Object value = map.get(key);
// Here the value is again a HashMap
               HashMap valuesMap=(HashMap)value;
               System.out.println("KEY" + key.toString() );
               if(valuesMap!=null)
                    Set set = valuesMap.keySet();
                    Iterator setit = set.iterator();
                    while (setit.hasNext())
                         Object keyinMap=setit.next();
                         Object valueinMap=valuesMap.get(key);
                         System.out.print("value is"+valueinMap);
Can anybody help me in this regard.
Thanks in advance

Hmm, this looks pretty good to me. What behavior does this give you? For example, do you see "KEYname" printed? Are you sure that "map" is actually the same one you added "secondMap" to?

Similar Messages

  • How to put values in a HashMap dynamically using a ArrayList as 'value'

    i have to generate different maps dynamically by passing arraylist (which is also dinamically increasing) in the value.
    i want to use :
    List myList=new ArrayList();
    for(..........){
    Map mymap=new HashMap();
    myMap.put(key, myList.add(objectBean));
    =====================================================================================================
    this line is giving error :
    myMap.put(String , myList.add(objectBean));
    it says myList.add(objectBean) is boolean where as it should be put(String, ObjectBean).

    None of this makes any sense whatsoever. You're creating a new map per loop iteration, you're using an apparently constant key, and you're adding something that's a boolean when you should be adding an ObjectBean (according to you).

  • How to print value with ""

    Hi All,
    I am trying to print a String with "Value" can anyone please provide me a code sample for that.
    What I am trying to print is -
    String Result = "a" + "b";
    System.out.println("Result = " + Result );
    This is giving me Result = ab
    Where as I want Result = "ab"
    Thanks in Advance
    Sameer

    public static void main(String[] args)
            String result = "\"ab\"";
            System.out.println( result );
        }The " is a special character in java. If you want to add a " to a string you must first escape it with a slash like so \"

  • How to print values of all my arguments automatically

    within a procedure, I am thinking of printing the values of all arguments for debugging.
    is there a way to do this in general,
    without having to print each one explicitly.
    many of my procedures can have dozens of arguments.
    all my arguments are simple, varchar2, number, date.
    but if there are ways to print compound arguments such as record,
    collection,cursor, etc. that would be a great trick too.
    create procedure p(p1 in varchar2, p2 in varchar2) is
    begin
    dbms_output.put_line('p1=' || p1);
    dbms_output.put_line('p2=' || p2);
    --logic of this procedure here
    end;
    dbms_describe can give me a list of argument names, data types and modes (IN, OUT or IN OUT).
    Thanks for any pointers!

    One approach is to have an array of VARCHAR2's and then at the start of each procedure write your parameters into the array and call a procedure. The procedure checks if debugging is switched on and if so prints out the parameters. Switching debug on and off is probably best done with a user context.
    e.g.
    Create or replace package debug_pkg is
      param_tab is table of varchar2(4000) index by binary_integer;
      params param_tab;
      procedure set_debug(p_debug BOOLEAN);
      function is_debug_on return BOOLEAN;
      procedure print_params;
    elsewhere
    create or replace procedure process_overdue (p_cust_id IN NUMBER, p_start_date IN DATE, p_invoice_no IN VARCHAR2) IS
    BEGIN
      debug_pkg.params(1) := 'PROCEDURE process_overdue';
      debug_pkg.params(2) := to_char(p_cust_id);
      debug_pkg.params(3) := to_char(p_start_date);
      debug_pkg.params(4) := p_invoice_no;
      debug_pkg.print_params;
    ...

  • How to print value of the variable in mail

    Hi,
    I am new to workflow and trying out some basis small work.
    i have created workflow for material change.
    whenever a material is changed mail is sended to user.
    it is working fine .
    but now i want that material number which is changed should come in mail.
    how can i achive this
    Thanks,
    Chintan

    Hi Soni
    You have the "Materialnumber" field in the event container. Pass this into the workflow container by defining a Workflow Container element and subsequently use this container as a variable in your email using insert fields option and you will have the Materialnumber visible in your mail sent.
    NB. This message is more or less a cut and paste from an other answer in this forum. So sometimes the fastet way to get an answer, is to search instead of posting questions. Just a kind reminder |
    Kind regards
    Mikkel

  • How To Print Field Value in TOP-OF-PAGE During Line Selection.

    How To Print Field Value in TOP-OF-PAGE During Line Selection when double click on field.

    (If my memory serves me well (not used for long time ago)
    Assign values to system fields sy-tvar0 - sy-tvar9, they will replace the placeholders "&0" through "&9" in the list headers and column headers.
    TOP-OF-PAGE DURING LINE-SELECTION.
         WRITE: / 'Interactive Report &3'.
      WRITE record-vbeln TO sy-tvar3.
    Regards,
    Raymond

  • How to get the value in a hashmap with a key of expression "123-456"?

    Hi all,
    I new to java and having a problem with getting values from a hashmap.here is the code which i wrote
    Map map = new HashMap();
    int m = 123;
    int n = 456;
    String key = String.valueOf(m) + "-" + String.valueOf(n);
        map.put(key, true);
        Now i am trying to get the value and i get an exception
    boolean b = map.get(String.valueOf(m) + "-" + String.valueOf(n));Can someone help me how to pass this expression as key in the hashamp

    Hi corlettk,
    Thanks for your reply. I have defined my map as Map<String, Boolean> selectedIds = new HashMap<String, Boolean>();
                selectedIds.put("123-456", true);           
                int m=123; int n=456;
                                     selectedIds.put(String.valueOf(m) + "-" + String.valueOf(n),true);
                boolean viv = selectedIds.get("String.valueOf(m)-String.valueOf(n)");
                System.out.println(viv);
                My problem is the hashmap key must be set dynamically ("123-456" is just an example) and when i get the value i should be able to pass those varibales in an expression correctly. Please let me know how can i pass an expression like the one above as a hashmap key. Please advise.

  • How to print Jtable values in one A4 size paper

    Hi,
    i am having JPanel , this panel have Jtbale, Jtextfield, Jlable, i search the code for Printing Jpanel, its work fine and print whole JPanel including, jtable, textbox, everything.
    my Jtable have Scroll bar to see all the values in the table,my problem is when i was print the JPanel the Jtable print only the display values in Jtable, cannot print all the values from Jtable,(eg. Jtable have 50 rows, screen display 20 rows only, move the scrollbar to see remaining,) .
    i want to print 50 rows how to print the values anyone can help me
    thanks in advance.

    Duplicate post. Mods please do your duty.

  • How to print the HEX values of non-displayable characters!

    I am trying to tokenize a string that contains non-displayable characters i.e. EBCDIC or ASCII. How can I print the HEX values of the non-displayable characters. e.g.
    "StartTEST1TEST2TEST3TEST4TEST5TEST6TEST7TEST812END"
    How can print the HEX values of in the above string. Any help is appreciated.
    Thanks

        char ch = 28; // or whatever character you want to look at.
        String hexString = Integer.toHexString(ch);
        System.out.println(hexString);

  • How to print the values of type Object?

    Hi All,
    I am not able to print values of the following can anyone telme where i am wrong and what i can do in this regard.
    Object one = request.getAttribute("values");
    When i try to print these values as following
    System.out.println("one ="+one);
    am not getting the values in a different format something like [Ljava.lang.String;@1234f. I tried to convert the following Object to String still its not working. Can some one please suggest me what i can do in this regard.
    Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    ferrari_sun wrote:
    I am getting a Null pointer exception if i typecast it to a string array. Not sure what to do nowThe hell you are. You don't get Null pointers out of casting. However you might be accessing null elements of the array afterwards.
    You really should throw away the code, go fetch some "How to learn basic Java with Wiggles The Bear" ebook and then start learning the basics instead of tripping on every single line of your code which is too complicated for you.

  • How to print the value if a condition is satisfied

    Hi,
    Please suggest me how to print a text as 'Do not print' when a field in the selection screen is entered.
    If in the selection screen (s_field1) we have  entered a value as ZESM then the value filed of
    wa_vbak-auart should check the the values in s_field1 then it should just print the text "'DO NOT PRINT''.
    we have written the folowing code, but the condition is not working.
    DATA: V_FIELD1 type z_field1. "(zdata element).
    ranges: r_fIELD1 for v_field1.
    SELECT-OPTIONS: S_field1 FOR v_field1 default 'ZESM'.
    loop at s_field1.
        r_field1-sign = 'I'.
        r_field1-option = 'EQ'.
        r_field1-low = s_field1-low.
        append r_field1.
        clear r_field1.
      endloop.
        if wa_vbak-auart in r_field1.
          wa_final-v_text = 'DO NOT PRINT'
        else.
          wa_final-v_text = ' '.
        endif.
    Please suugest what can be done.
    Thanks in advance

    Hi,
    if wa_vbak-auart in r_field1.
    wa_final-v_text = 'DO NOT PRINT'
    else.
    wa_final-v_text = ' '.
    endif.
    Have you writtent he above code with in loop enloop on the internal table.If yes then simply add append statement after assignment.
    if wa_vbak-auart in r_field1.
    wa_final-v_text = 'DO NOT PRINT'
    append wa_final into it_final.
    clear wa_final.
    else.
    wa_final-v_text = ' '.
    append wa_final into it_final.
    clear wa_final.
    endif.
    Hope this will solve your problem.
    Pooja

  • How to print the value of a field of  type FLTP

    hi experts,
    pls tell me how to print the value of a field of  type FLTP. i.e in decimal format not in exponential format.
    thankyou.
    krishna

    Hi ,
    I dont think in Floating point u can able to go for the decimal point display as it is for the minimum precission display..
    Define the variable as the 'packed' type and then u can able to define the decimal point...
    Cheers,
    SImha.

  • How to keep value in arrayList and print into matrix form.

    compute all primes less than N, and display the results
    step by step .summarize the computed results in an easy-to-read format.(matrix)
    The program starts by asking for an integer value N from the user. Print out the initial matrix
    of numbers from 2 to N.
    To find all primes less than N, begin by making a table of integers from 2 to N.
    Find the smallest integer i, that is NOT prime and NOT crossed out. Mark i as a prime
    number and cross out 2i, 3i, 4i, ?, ni N.
    At this point, program should print the intermediate results in a matrix format, and pause
    until any key is pressed before proceeding.clear screen every
    time prior to printing the intermediate results (in the matrix format).
    When i > N , the algorithm terminates. screen is cleared once again,
    before the program prints the final results in the matrix format.
    Following are the requirements for the matrix format:
    - The matrix consists of 10 columns
    - The number of rows varies, depending on the input N
    - Initial matrix: The program prints an empty string in place of 1
    - Intermediate matrix: The program prints values for all prime numbers and numbers
    that are not crossed out. The program prints an empty string for each crossed-out
    number.
    Final matrix: The program prints only the prime numbers less than N
    P.S I want to write at least 3 classes

    This is my new first class but it have an error
    import java.io.*;
    import java.util.*;
    public class ArrayListExample2 {
        public static void main(String[] args)throws IOException {
            ArrayListExample listExample = new ArrayListExample();
            listExample.doArrayListExample();
        public void doArrayListExample()throws IOException {
              BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
             System.out.print("enter limit : ");
              int max=Integer.parseInt(br.readLine());
              System.out.println();
            int counter = 2;
            List listA = new ArrayList();// int list
            //List listB = new ArrayList(); //string list
            for (int i = 2; i <= max; i++) {
                System.out.print("\t" + i );
                listA.add(new Integer(i)); //???????2-max ??listA
              int count =0;
              BufferedReader en = new BufferedReader(new InputStreamReader(System.in));
              while(count<Math.sqrt(max))
                     // max may be number of input or size of array list
              //BufferedReader en = new BufferedReader(new InputStreamReader(System.in));
              System.out.println ("Please enter");
              en.readLine();// wait for enter
              listA.removeNotPrime();
              count++;
         public void removeNotPrime()// what parametor?Need?
              for (int i=0;i<Math.sqrt(max)))
                   int prime = listA.get(i);
                        for (int j=i+1;i<=listA.size();j++)
                         int val = listA.get(j);
                        if (val%prime==0)
                        listA.remove(j);
    This part for test
            for (int i = 0; i <= max; i++)  // printttttttttt
                //System.out.print("\t" + i );
                   System.out.print("\t" + listA.get(i);
                // call class printMatrix;
    }

  • How to print a bullet in smartforms?

    Hi All,
    How to print a bullet in smartforms?
    I need it urgently.
    Any help would be appeciated.
    Regards,
    Mahesh.

    Hi,
    if i remember correct <600> is the value for bullets.
    you can insert this using sap system symbols ---> select bullets (before this place your cursor where ever you want the bullets.
    eg:
    P1  <600> test.
    Thanks,
    Sree.

  • How to print Integrity sql in the preparedstatement?

    How to print Integrity sql in the preparedstatement?
    Connection conn = null;
    String sql = "select * from person where name=?";
    PreparedStatement ps = conn.prepareStatement(sql);
    ps.setObject(1, "robin");
    ps.executeQuery();
    i'm wants print Integrity sql.
    For example:select * from person where name='robin'
    How should I do?
    thanks a lot!

    PreparedStatement doesn't offer methods for that. You can write your own implementation of PreparedStatement which wraps the originating PreparedStatement and saves the set* values and writes it to the toString().
    If needed, myself I just print the sql as well as the values-being-set to the debug statement.Logger.debug(query + " " + values);

Maybe you are looking for

  • List view in I phone calendar

    Since my last update, I've been unable to access the "list" view in the I phone calendar. I can access event list by day, and can search for specific events, but can no longer scroll through a full list of all events in my calendar. Does anyone know

  • What is the difference between apple warranty and applecare and applecare plus

    I understand that apple warranty covers damage due to manufacture defects and applecare is the extended warranty and insurance. Then what is applecare+? What is the difference between applecare and applecare+?

  • Daily sequence number

    Hi, I need a clean solution for a daily sequence number (starts from 1 everyday). Clean in the sense that upon initial setup, I do not have to do anything and I can get my number everyday by just one jdbc call/query. Thank you in advance.

  • Can I get a black keyboard in ios7

    I have noticed in ios7 there are certain instances when the iphone/ipad keyboard turns black in color, for example when you enter your password into the itunes store to buy an app. Is it possible to get the keyboard this color permanently? Thanks.

  • Help! SQL Qs.

    i have 3 tables. ACCOUNT: (pk)AccountId, userName ORDERS: (pk)orderId, (pk1)accountId lineItems: (pk,fk1)orderId, (pk, Fk2)productId im trying to insert using: sql.append("INSERT INTO lineItems "); sql.append("(orderId, productId, qtyOrdered, unitPri