[英]Is there a way to compare two Strings with each other using java streams?
此方法比较两个字符串。 其中之一来自物体。 如果字符串匹配,则ID由对象返回。
private static Long getDefaultKag(Long mandandId) {
List<MandantKagAccountEntity> mandantKagAccountEntities = new MandantKagAccountManager().findAllKags(mandandId);
for (MandantKagAccountEntity mandantKagAccountEntity : mandantKagAccountEntities) {
if (mandantKagAccountEntity.getKagText().equals("Default_kag")) {
return mandantKagAccountEntity.getMandantKagId();
}
}
return null;
}
有什么办法可以解决流? 我的方法,但我无能为力了。
private static long getDefaultKag(Long mandandId) {
return new MandantKagAccountManager().findAllKags(mandandId).stream()
.filter(m -> m.getKagText().equals("Default_Kag"))
...
...
...
}
你有解决的办法吗? 我还想知道两个变体中的哪个变体对于大量数据更有效。
更换
...
...
...
同
.map(MandantKagAccountEntity::getMandantKagId)
.findFirst()
.orElse(null);
我认为它将成功
private static long getDefaultKag(Long mandandId) {
MandantKagAccountManager mandantKagAccountManager=new MandantKagAccountManager().findAllKags(mandandId).stream()
.filter(m -> m.getKagText().equals("Default_Kag")).findFirst()
.orElse(null);
if(mandantKagAccountManager!=null)
return mandantKagAccountManager.getMandantKagId()
return null;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.