0

I am trying to do a stream() filter to only pull records where the string FedwireTagLabel field is greater than "1520". here is the code that I currently have:

         FedwireMessage filterFinancials = financialMessageRecords.stream()
            .filter(e -> e.getFedwireTagLabel() >= "1520")
            .findAny()
            .orElse(null);

This is an error. Do you know what is the processing in stream().filter() that you can do for a greater than or equal to on a string field?

Thanks again

luthfianto
  • 1,746
  • 3
  • 22
  • 37
hammerva
  • 129
  • 1
  • 14

1 Answers1

1

You are comparing two String here. You need to convert the label to an Integer.

 FedwireMessage filterFinancials = financialMessageRecords.stream()
            .filter(e -> Integer.parseInt(e.getFedwireTagLabel()) >= 1520)
            .findAny()
            .orElse(null);

Indeed, using >= on String call the method CompareTo which return -1, 0 or 1 according to the alphabetic default comparison.

For more info, look at this post.

Best

Maxouille
  • 2,729
  • 2
  • 19
  • 42