Ich bin neu in Java und ich habe unten HashMapList Liste erklärt.Wie sortiere ich List <HashMap <String, String >> ls in Java?
List<HashMap<String, String>> hashMapList = new ArrayList<HashMap<String, String>>();
Ich habe ein anderes Verfahren hergestellt insertData
die Daten in hashMapList zu setzen.
Ich habe auch eine andere Liste psData
machen.
so dass zum Einfügen der Liste in HashMapList ich unten Code verwenden.
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);
Jetzt bin ich möchte, dass hashMapList mit coa Eigenschaft filtern, die ich in insert Methode übergeben haben.
ist dies in Java möglich? Bitte hilf mir. Danke, ich habe mein Bestes versucht, aber ich verstehe es nicht.
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;
}
Verwenden Sie 'Collections.sort()' zusammen mit einem 'Comparator
@Thomas kannst du mir bitte das Beispiel geben – ADMIN
Huch: Eine Methode mit so vielen Parametern ist immer zweifelhaft. Zum Beispiel ist es sehr einfach, zwei Parameter in der falschen Reihenfolge zu übergeben, und Sie werden es nicht bemerken. Sie sollten das [Builder-Muster] (https://en.wikipedia.org/wiki/Builder_pattern) in Erwägung ziehen. –