We have two lists one is of type Question
and the other of type Tag
.
The Question class has those attributes
private String id;
private String header;
private String content;
private List<Tag> tags;
private Long timeStamp;
The Question list has several questions in it and the Tag list has all tags in it. We wanna check if One question contains any tag of the tag list. I want to do this for all questions.
With question.getTags
, I get the list of tags.
I tried
List<Question> allQuestions = ... ; // List of type questions
List<Tags> alltags = ... ; // List of type tag
for(Question question: allQuestions) {
for(Tag tag: allTags){
if(question.getTags().contains(tag)) {
//do something
}
}
}
This is not quite doing what I want to do, I think I have to do something with streams but I could not quite figure out how I exactly have to write the code.