java 数字、英文、中文混排排序

按照数字,字母,中文拼音首字母顺序排序

public static void main(String[] args) {
        List<QuotationBrandResult> quotationBrands = new ArrayList<>();
        QuotationBrandResult brandResult = new QuotationBrandResult("ABS", "0125H", "B啊弄咯");
        quotationBrands.add(brandResult);

        brandResult = new QuotationBrandResult("ABS", "2125H", "啊弄咯");
        quotationBrands.add(brandResult);

        brandResult = new QuotationBrandResult("ABS", "2125H", "的弄咯");
        quotationBrands.add(brandResult);

        brandResult = new QuotationBrandResult("ABS", "c125H", "C弄咯");
        quotationBrands.add(brandResult);

        Comparator<Object> CHINA_COMPARE = Collator.getInstance(java.util.Locale.CHINA);
        quotationBrands.sort((o1, o2) -> ((Collator) CHINA_COMPARE).compare(o1.getSortKeys(), o2.getSortKeys()));

        for (QuotationBrandResult quotationBrand : quotationBrands) {
            System.out.println(quotationBrand.getSortKeys());
        }
    }
@Data
public class QuotationBrandResult {

    @ApiModelProperty("品名")
    private String prodCategory;

    @ApiModelProperty("牌号")
    private String brandName;

    @ApiModelProperty("厂家")
    private String produceEnterprise;

    @ApiModelProperty("目的用来排序的品名-牌号-厂家")
    private String sortKeys;

    public QuotationBrandResult() {
    }

    public QuotationBrandResult(String prodCategory, String brandName, String produceEnterprise) {
        this.prodCategory= prodCategory;
        this.brandName= brandName;
        this.produceEnterprise = produceEnterprise;
        this.sortKeys = prodCategory+ "-" + brandName+ "-" + produceEnterprise;
    }

}

java 数字、英文、中文混排排序_第1张图片

你可能感兴趣的:(笔记,java)