How java merges the results of multiple queried list collections into one list collection.

queries several list collections, but the final result is all the data from several collections

listlistphoneMap

list

how to write code!

Mar.29,2021
The

addAll method is not allowed?


List's addAll method is fine. Use one of the List to add other List to it using the addAll method.


this looks strange. Why not directly select phone,createTime,money,day from table.
to achieve the results to meet your needs


look at the description and comments of the subject, I think this is what the database can do. Three tables are finally displayed in a single table through a multi-table query, which can be done through the sql statement. This should not be what the Java language should do. It is recommended that the subject modify the problem description to describe the problems related to database queries.


I don't know if it's what you mean

public class testlist {
    private static ArrayList<List> list1 = new ArrayList<List>();//
    private static ArrayList<List> list2 = new ArrayList<List>();//
    private static ArrayList<List> list3 = new ArrayList<List>();//

    public static void main(String[] args) {
        //
        setUpData();
        for (int i = 0 ; i < list1.size(); iPP){
            list1.get(i).setMoney(list2.get(i).getMoney());
            list1.get(i).setDay(list3.get(i).getDay());
        }
        for (List item : list1){
            System.out.println(item.toString());
        }
    }

    public static void setUpData(){
        //
        List s1 = new List("1234","122312",null,null);
        List s2 = new List("1235","32134321",null,null);
        List s3 = new List("1324","423424",null,null);
        List s4 = new List("1325","111111111",null,null);
        list1.add(s1);
        list1.add(s2);
        list1.add(s3);
        list1.add(s4);
        //
        List s5 = new List("1234",null,"3141241",null);
        List s6 = new List("1235",null,"42134134",null);
        List s7 = new List("1324",null,"123513",null);
        List s8 = new List("1325",null,"222222222",null);
        list2.add(s5);
        list2.add(s6);
        list2.add(s7);
        list2.add(s8);
        //
        List s9 = new List("1234",null,null,"22");
        List s10 = new List("1235",null,null,"33");
        List s11 = new List("1324",null,null,"11");
        List s12 = new List("1325",null,null,"44");
        list3.add(s9);
        list3.add(s10);
        list3.add(s11);
        list3.add(s12);
    }



}


let list = list1.map((item, index) => {
    for(let attr in item) {
      let value = item[attr] || list2[attr] || list3[attr];
      item[attr] = value;
    }
    
    return item;
} )

write a javabean, with phone,createtime,money,day attributes

Menu