誰かが私を助けることを願っています。私はInvoice
クラスのArrayList
を持っています。私が得ようとしているのは、このArrayList
をフィルタリングし、そのプロパティの1つがregex
と一致する最初の要素を見つけることです。regexが動作しないJavaストリームフィルタ
public class Invoice {
private final SimpleStringProperty docNum;
private final SimpleStringProperty orderNum;
public Invoice{
this.docNum = new SimpleStringProperty();
this.orderNum = new SimpleStringProperty();
}
//getters and setters
}
私は整数の形式を持っていないorderNum
プロパティに任意の値があるかどうか見つけるために、このregex
(\\D+)
でフィルタリングしています: Invoice
クラスは次のようになります。 だから基本的に私はこのストリームを使用しています
Optional<Invoice> invoice = list
.stream()
.filter(line -> line.getOrderNum())
.matches("(\\D+)"))
.findFirst();
しかし、それは動作しません。何か案が? 私が検索してきたと私はthisようpattern.asPredicate()
を使用する方法が見つかりました:
Pattern pattern = Pattern.compile("...");
List<String> matching = list.stream()
.filter(pattern.asPredicate())
.collect(Collectors.toList());
Integer
のList
、String
などで、私はPOJO
でそれを行う方法を発見していません。 ご協力いただければ幸いです。 ニースの日
java8ストリームは、何の 'matches'方法を持っていない、このコードが有効ですか? – ByeBye