I need add sequence number to a list of object based on created date field Code is written in Java 11. I have a list like the below one
public class UserInformation {
private String userSeqNumber;
private String userDepartment;
private Date createdDate;
}
I can sort the list by created date but at the same time i need to add the userSequenceNumber based on the created date in ascending order. I tried a messed up code here, can someone please help me.
userInformations.stream()
.filter(c-> c.getUserDepartment().equalsIgnoreCase(request.getUserDepartment()))
.sorted(Comparator.comparing(UserInformation::getCreatedDate))
.forEach(f -> f.setUserSeqNumber());
So output should be for each department, sequence number should be incremented based on the number of entries using the created date.
UserInformation:[{"1","IT",01-01-2022}, {"2","IT",01-02-2022},{"1","OPS",01-01-2022}, {"2,"OPS",01-02-2022}]
setReferralSeqNumber()produces some output, the posted code is not capable of producing output. Unless your problem is precisely that this code doesn’t produce any output, you should add an explanation about your actual problem, i.e. in what regard does the code not do what you expect.SIUInformation? I thought you were simply sorting dates amongst themselves. Please provide more detail and include input and expected output. BTW, most of theDateclass is mostly deprecated.LocalDatewould be much better unless you must use legacy classes.