Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何对列表进行排序<;HashMap<;字符串,字符串>&燃气轮机;java中的ls?_Java_Arraylist - Fatal编程技术网

如何对列表进行排序<;HashMap<;字符串,字符串>&燃气轮机;java中的ls?

如何对列表进行排序<;HashMap<;字符串,字符串>&燃气轮机;java中的ls?,java,arraylist,Java,Arraylist,我是java新手,我在下面声明了hashMapList List<HashMap<String, String>> hashMapList = new ArrayList<HashMap<String, String>>(); 因此,对于在hashMapList中插入列表,我使用了下面的代码 HashMap<String, String> psData = new HashMap<String, String>(); s

我是java新手,我在下面声明了hashMapList

List<HashMap<String, String>> hashMapList = new ArrayList<HashMap<String, String>>();
因此,对于在hashMapList中插入列表,我使用了下面的代码

HashMap<String, String> psData = new HashMap<String, String>();

so for insert the list in hashMapList i have use below code.

psData = insertData(payment.getDocumentNo(), payment.getId(),
                  payment.getPaymentDate(), creditLeft, payment.getBusinessPartner(), group,
                  recOrPay.equals("RECEIVABLES") ? paymentInTab : paymentOutTab, dateFormat, true,
                  BigDecimal.ZERO, addressline1, addressline2, City, postalcode, state, email,
                  phoneno, payment.getAmount(), duration, discount,
                  payment.getFinancialTransactionAmount(), payment.getWriteoffAmount(),
                  Outstandings, Coa, Ev);
              hashMapList.add(psData); 
HashMap psData=newhashmap();
因此,对于在hashMapList中插入列表,我使用了下面的代码。
psData=insertData(payment.getDocumentNo(),payment.getId(),
payment.getPaymentDate(),creditLeft,payment.getBusinessPartner(),group,
recOrPay.equals(“应收款”)?paymentInTab:paymentOutTab,日期格式,true,
BigDecimal.ZERO、addressline1、addressline2、城市、邮政编码、州、电子邮件、,
电话号码,payment.getAmount(),持续时间,折扣,
payment.getFinancialTransactionAmount(),payment.getWriteoffAmount(),
未偿贷款(Coa、Ev);
hashMapList.add(psData);
现在,我想使用传入insertData方法的coa属性过滤hashMapList

这在java中可能吗?请帮帮我。 谢谢你,我已经尽力了,但我不明白

private HashMap<String, String> insertData(String documentNo, String id, Date date,
      BigDecimal amount, BusinessPartner bpartner, int group, String tabId,
      SimpleDateFormat dateFormat, boolean credits, BigDecimal doubtfulDebt, String Address1,
      String Address2, String Zip, String City, String State, String Email, String Phone_h,
      BigDecimal InvoiceAmount, int Durations, BigDecimal Discount, BigDecimal Payments,
      BigDecimal Writeoffs, BigDecimal Outstandings, String Coa, ElementValue ev) {
    HashMap<String, String> psData = new HashMap<String, String>();
    psData.put("INVOICE_NUMBER", documentNo);
    psData.put("INVOICE_ID", id);
    psData.put("INVOICE_DATE", dateFormat.format(date));
    psData.put("AMOUNT" + group, amount.compareTo(BigDecimal.ZERO) == 0 ? null : amount.toString());
    psData.put("DOUBTFUL_DEBT",
        doubtfulDebt.compareTo(BigDecimal.ZERO) == 0 ? null : doubtfulDebt.toString());
    BigDecimal percentage = calculatePercentage(amount.add(doubtfulDebt), doubtfulDebt);
    psData.put("PERCENTAGE",
        percentage.compareTo(BigDecimal.ZERO) == 0 ? null : percentage.toString());
    if (credits) {
      psData.put("SHOW_NETDUE", amount.add(doubtfulDebt).toString());
    } else {
      psData.put("NETDUE", amount.add(doubtfulDebt).toString());
      psData.put("SHOW_NETDUE", amount.add(doubtfulDebt).toString());
    }
    psData.put("BPARTNER", bpartner.getId().toString());
    psData.put("BPARTNERNAME", bpartner.getIdentifier().toString());
    psData.put("TABID", tabId);
    psData.put("address1", Address1);
    psData.put("address2", Address2);
    psData.put("zip", Zip);
    psData.put("city", City);
    psData.put("state", State);
    psData.put("email", Email);
    psData.put("phone_h", Phone_h);
    psData.put("invoiceamount",
        InvoiceAmount.compareTo(BigDecimal.ZERO) == 0 ? "-" : InvoiceAmount.toString());
    psData.put("durations",
        Integer.toString(Durations).equals("0") ? "-" : Integer.toString(Durations));
    psData.put("payments", Payments.compareTo(BigDecimal.ZERO) == 0 ? "0.00" : Payments.toString());
    psData.put("writeoffs",
        Writeoffs.compareTo(BigDecimal.ZERO) == 0 ? "0.00" : Writeoffs.toString());
    psData.put("outstandings",
        Outstandings.compareTo(BigDecimal.ZERO) == 0 ? "0.00" : Outstandings.toString());
    psData
        .put("discounts", Discount.compareTo(BigDecimal.ZERO) == 0 ? "0.00" : Discount.toString());
    psData.put("coa", Coa);
    psData.put("ev", ev.getId());
    return psData;

  }
private HashMap insertData(字符串文档编号、字符串id、日期、,
BigDecimal金额、业务伙伴bpartner、整数组、字符串选项卡ID、,
SimpleDataFormat dateFormat、布尔积分、BigDecimal DoubfulDebt、字符串地址1、,
字符串地址2、字符串Zip、字符串城市、字符串州、字符串电子邮件、字符串电话、,
BigDecimal发票金额、整数期限、BigDecimal折扣、BigDecimal付款、,
BigDecimal Writeoffs、BigDecimal未决、字符串Coa、元素值ev){
HashMap psData=新的HashMap();
psData.put(“发票号”,文件号);
psData.put(“发票ID”,ID);
psData.put(“发票日期”,dateFormat.format(日期));
psData.put(“AMOUNT”+组,AMOUNT.compareTo(BigDecimal.ZERO)==0?null:AMOUNT.toString());
psData.put(“可疑债务”,
DoubleFulDebt.compareTo(BigDecimal.ZERO)==0?null:DoubleFulDebt.toString();
BigDecimal percentage=计算百分比(amount.add(可疑债务),可疑债务);
psData.put(“百分比”,
percentage.compareTo(BigDecimal.ZERO)==0?null:percentage.toString();
国际单项体育联合会(学分){
psData.put(“SHOW_NETDUE”,amount.add(do疑债务).toString());
}否则{
psData.put(“NETDUE”,amount.add(可疑债务).toString());
psData.put(“SHOW_NETDUE”,amount.add(do疑债务).toString());
}
put(“BPARTNER”,BPARTNER.getId().toString());
put(“BPARTNERNAME”,bpartner.getIdentifier().toString());
psData.put(“TABID”,TABID);
psData.put(“地址1”,地址1);
psData.put(“地址2”,地址2);
psData.put(“zip”,zip);
psData.put(“城市”,城市);
psData.put(“状态”,状态);
psData.put(“电子邮件”,email);
psData.put(“phone_h”,phone_h);
psData.put(“发票金额”,
InvoiceAmount.compareTo(BigDecimal.ZERO)=0?”-“:InvoiceAmount.toString());
psData.put(“持续时间”,
Integer.toString(持续时间).equals(“0”)?“-”:Integer.toString(持续时间));
psData.put(“payments”,payments.compareTo(BigDecimal.ZERO)==0?.00”:payments.toString();
psData.put(“冲销”,
Writeoffs.compareTo(BigDecimal.ZERO)=0?.00:Writeoffs.toString();
psData.put(“未完成”,
Outstandings.compareTo(BigDecimal.ZERO)=0?.00:Outstandings.toString();
psData
.put(“折扣”,折扣.compareTo(BigDecimal.ZERO)=0?.00:折扣.toString());
psData.put(“coa”,coa);
psData.put(“ev”,ev.getId());
返回psData;
}
基于问题(而不是基于关于排序的标题)。您需要一个基于coa(科目表)筛选列表的解决方案

希望您正在使用Java8

        List<Map<String,String>> list = new ArrayList<>();

        Map<String,String> map = new HashMap<>();
        map.put("prop1", "value1");
        map.put("prop2", "value2");
        map.put("coa", "value3");
        list.add(map);

        map = new HashMap<>();
        map.put("prop1", "value1");
        map.put("prop2", "value2");
        map.put("coa", "value3");
        list.add(map);

        map = new HashMap<>();
        map.put("prop1", "v1");
        map.put("prop2", "v2");
        map.put("coa", "v3");
        list.add(map);

        List<Map<String,String>> listMapWithProp3EqualValue3 = list.stream()
                .filter(p -> p.get("coa").equals("value3")).collect(Collectors.toList());

        System.out.println("Filtered List with coa=value3 :" + listMapWithProp3EqualValue3);

        listMapWithProp3EqualValue3 = list.stream()
                .filter(p -> p.get("coa").equals("v3")).collect(Collectors.toList());

        System.out.println("Filtered List coa=v3 :" + listMapWithProp3EqualValue3);
List List=new ArrayList();
Map Map=newhashmap();
地图出售(“prop1”、“value1”);
map.put(“prop2”、“value2”);
map.put(“coa”、“value3”);
列表。添加(地图);
map=新的HashMap();
地图出售(“prop1”、“value1”);
map.put(“prop2”、“value2”);
map.put(“coa”、“value3”);
列表。添加(地图);
map=新的HashMap();
地图放置(“prop1”、“v1”);
地图放置(“prop2”、“v2”);
map.put(“coa”、“v3”);
列表。添加(地图);
List listMapWithProp3EqualValue3=List.stream()
.filter(p->p.get(“coa”).equals(“value3”).collect(Collectors.toList());
System.out.println(“coa=value3的过滤列表:”+listMapWithProp3EqualValue3);
listMapWithProp3EqualValue3=list.stream()
.filter(p->p.get(“coa”).equals(“v3”).collect(Collectors.toList());
System.out.println(“过滤列表coa=v3:+listMapWithProp3EqualValue3”);
我正在将列表转换为流,并使用lambdas对其进行过滤

如果您没有使用Java8,请检查以下内容

它允许您筛选集合


希望它能帮助您。

我已经解决了我的问题,谢谢

Collections.sort(hashMapList, new Comparator<HashMap<String, String>>() {
            public int compare(HashMap<String, String> mapping1, HashMap<String, String> mapping2) {
              return mapping1.get("coa").compareTo(mapping2.get("coa"));
            }
          });
Collections.sort(hashMapList,newcomparator(){
公共int比较(HashMap映射1、HashMap映射2){
返回mapping1.get(“coa”).compareTo(mapping2.get(“coa”));
}
});

使用
Collections.sort()
和一个
比较器
,该比较器从映射中提取正确的值并对其进行比较。@Thomas你能给我举个例子吗。例如,很容易以错误的顺序传入两个参数,您不会注意到。你也应该考虑使用它。你还应该考虑定义一个类来将数据保存在良好类型的字段中:一个<代码> map < /COD>是一个非常简单的方法来存储这样的异构数据。(也就是说,您必须将所有内容都设置为
字符串
,以将其存储在地图中,即使您将某些值指定为
BigDecimal
业务伙伴
)。我
Collections.sort(hashMapList, new Comparator<HashMap<String, String>>() {
            public int compare(HashMap<String, String> mapping1, HashMap<String, String> mapping2) {
              return mapping1.get("coa").compareTo(mapping2.get("coa"));
            }
          });