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

  • Home
  • SEARCH
  • 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 9033393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:13:12+00:00 2026-06-16T08:13:12+00:00

I Have two Lists each containing rows from sql query containing 2 elements(columns) operator

  • 0

I Have two Lists each containing rows from sql query containing 2 elements(columns) operator and id
i want to map operator with both the lists and prints id from both the lists(ids will be different corresponding to operator in both the lists)

operator can not be key in this situation.

    **List 1**            **Lists 2**
  operator1, id1       operator4, id7
  operator1, id2       operator3, id8
  operator2, id3       operator2, id9
  operator2, id4       operator2, id10
  operator3, id5       operator1, id11
  operator4, id6       operator1, id12

final output should be something like this

    **List3**
operator1, id1,id2,id11,id12
operator2, id3,id4,id9,id11
operator3, id5,id8
operator4, id6,id7

in what way can i implement?

  • 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-16T08:13:14+00:00Added an answer on June 16, 2026 at 8:13 am

    Easiest way is to use Map to group by operators.Actually you can use Map instead of List but you can also iterate through map to append key and values and insert them back to the list. You can use the following code to achieve the result you want.

    public static void main(String[] args) {
        List<Object> list1 = new ArrayList<Object>();
        list1.add("operator1, id1");
        list1.add("operator1, id2");
        list1.add("operator2, id3");
        list1.add("operator2, id4");
        list1.add("operator3, id5");
        list1.add("operator4, id6");
    
        List<Object> list2 = new ArrayList<Object>();
        list2.add("operator4, id7");
        list2.add("operator3, id8");
        list2.add("operator2, id9");
        list2.add("operator2, id10");
        list2.add("operator1, id11");
        list2.add("operator1, id12");
    
        Map<String, String> map = new HashMap<String, String>();
        List<Object> list3 = new ArrayList<Object>();
    
        Iterator<Object> it1 = list1.iterator();
        Iterator<Object> it2 = list2.iterator();
    
        while (it1.hasNext() && it2.hasNext()) {
            String[] line1 = ((String) it1.next()).split(",");
            map.put(line1[0], map.get(line1[0]) == null ? line1[1] : map.get(line1[0]) + ", " + line1[1]);
    
            String[] line2 = ((String) it2.next()).split(",");
            map.put(line2[0], map.get(line2[0]) == null ? line2[1] : map.get(line2[0]) + ", " + line2[1]);
        }
    
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String item = entry.getKey() + "," + entry.getValue();
            System.out.println(item);
            list3.add(item);
        }
    }
    

    After running the code above the result will be :

    operator4, id6,  id7
    operator1, id1,  id2,  id11,  id12
    operator3, id5,  id8
    operator2, id3,  id4,  id9,  id10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 lists, and inside each are two more lists containing data frames
I have two grid views containing 12 and 24 rows resp. Each row contains
Say I have a list of edges each containing two nodes (to and from).
I have two lists. Both containing the same values: QStringList filePaths; filePaths.append(C:/backup); filePaths.append(C:/download/file1); filePaths.append(D:);
I have two tables containing data that are essentially headline lists from different sources.
I have two Lists of dictionaries. Both are not not null. How to merge
I have two lists: [a, b, c] [d, e, f] I want: [a, d,
I have two lists. They are sortable but not connected (elements of list one
We have two lists: a=['1','2','3','4'] b=['2','3','4','5'] How to get a list with elements that
I have two lists which are guaranteed to be the same length. I want

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.