Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8449199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:38:21+00:00 2026-06-10T10:38:21+00:00

I’ve a row in db returned by query below. Columns to select include rec,

  • 0

I’ve a row in db returned by query below. Columns to select include rec, head, amount. I want to sort the rows by head column. I tried Map where string for head and list for other two columns.

I’ve hit the wall with my non-working code posted below. How would I append another list to list of repeated key. Documentation says it replaces the value for same key whereas I need it appended to the list value. I would be really greatful for any help.

Query q= session.createQuery("select tally_receipt_prefix, tally_receipt_no, tally_head, tally_amount from Tally_table where tally_system_date='"+fmtd_date+"' and tally_dbcr_indicator='DB' and tally_mode='Ca' order by tally_head,tally_receipt_prefix,tally_receipt_no"); System.out.println("query "+q);

List heads=new ArrayList();

for(Iterator it=q.iterate(); it.hasNext(); )
{
    Object[] row= (Object[]) it.next();

    payincash1=new LinkedHashMap<String, List>();

    heads.add((String)row[2]);

    List tails = null;
    tails=new ArrayList();
    tails.add((String)row[0]);
    tails.add((String)row[1]);
    tails.add((String)row[3]);

    System.out.println("heads in dao from iter 1: "+heads);  
    System.out.println("tails in dao from iter1 on: "+tails);

    if(heads.contains((String)row[2]))  // for head in temp list
    {
        System.out.println("in first if");
        if(payincash1.containsKey((String)row[2]))     
        {
            System.out.println("map if repeat: "+payincash1);
            payincash1.put((String)row[2],tails);
        }

    } 
    else
    {

        System.out.println("map if not repeat: "+payincash1);
        payincash1.put((String)row[2], tails);

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:38:22+00:00Added an answer on June 10, 2026 at 10:38 am

    Sounds more like you want a list of lists

    Something like Map<String, List<List>>

    Then you’d end up with something like…

    Map<String, List<List>> payincash1 = new LinkedHashMap<String, List<List>>();
    
    heads.add((String) row[2]);
    
    List tails = null;
    tails = new ArrayList();
    tails.add((String) row[0]);
    tails.add((String) row[1]);
    tails.add((String) row[3]);
    
    System.out.println("heads in dao from iter 1: " + heads);
    System.out.println("tails in dao from iter1 on: " + tails);
    
    List master = payincash1.get((String)row[2]);
    if (master == null) {
    
        master = new List();
        payincash1.put((String)row[2], master);
    
    }
    
    master.add(tails);
    

    Now, personally, I’d be creating a “data” object that would contain all this information.

    public class MyData {
        private String rec, head, amount, ??; // Apparently you have another variable I don't know about
        public MyData(String rec, String head, String amount, String ??) {
            // Initalise...
        }
        // Setters and getters not inclueded
    }
    

    Then you could do something like this…

    Map<String, List<MyData>> payincash1 = new LinkedHashMap<String, List<MyData>>();
    
    MyData data = new MyData(row[0], row[1], row[2], row[3]);
    
    List master = payincash1.get((String)row[2]);
    if (master == null) {
    
        master = new List<MyData>();
        payincash1.put((String)row[2], master);
    
    }
    
    master.add(data);
    

    Which is a little cleaner (IMHO)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
Does anyone know how can I replace this 2 symbol below from the string
I want to construct a data frame in an Rcpp function, but when I
i want to parse a xhtml file and display in UITableView. what is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.