mardi 19 juillet 2016

Concatenate object values regarding name of fields in alphabetical order

I'm looking for a method to concatenate object values regarding name of fields in alphabetical order.

Example:

public Class Request {
    private String number;
    private String amount;
    private String currency;
}

Request request = new Request();
request.setNumber("tata");
request.setCurrency("toto");

With this, my method should return tototata.

Method must be generic:

public static String concatenate(Object object) { ...}

null values must not be concatenated.

I already checked out Apache Commons BeanUtils and Java 8 streams, but found nothing nice.





Aucun commentaire:

Enregistrer un commentaire