How to find an object in an ArrayList by property JAVA 8
This is how the data would look like, I wanted to fetch classCode = PP
{
"unitSet": "IMPERIAL",
"_class": "com.model.UnitSet",
"conversionFactors": [
{
"classCode": "GF",
"unit": "ft3/min",
"decimals": 2,
"factor": "2118.8802"
},
{
"classCode": "PP",
"unit": "psi",
"decimals": 1,
"factor": "0.000145038"
},
{
"classCode": "VE",
"unit": "ft/min",
"decimals": 1,
"factor": "196.8503937"
},
}
This is how I got the data using Java Streams
Hope this helps
This is how the data would look like, I wanted to fetch classCode = PP
{
"unitSet": "IMPERIAL",
"_class": "com.model.UnitSet",
"conversionFactors": [
{
"classCode": "GF",
"unit": "ft3/min",
"decimals": 2,
"factor": "2118.8802"
},
{
"classCode": "PP",
"unit": "psi",
"decimals": 1,
"factor": "0.000145038"
},
{
"classCode": "VE",
"unit": "ft/min",
"decimals": 1,
"factor": "196.8503937"
},
}
public class UnitSet { private String unitSet; private ListconversionFactors;
}
public class ConversionFactor { private String classCode; private String unit; private Integer decimals; private Float factor;
}
This is how I got the data using Java Streams
OptionalconversionFactor = unitSet.getConversionFactors() .stream() .filter(p -> p.getClassCode().equals(("PP"))) .findFirst();
Hope this helps
No comments:
Post a Comment