bahdotsh
bahdotsh

Reputation: 459

Iterating through a list which is an object of a table

public List<AnswerValues> getAllAnswers(Forms fm){
     Session sess = getSession();
     Criteria crit = sess.createCriteria(FormQuestions.class);
     crit.add(Restrictions.eq("fkformId",fm));
     List<FormQuestions> qs = crit.list();
}

The code is incomplete. I want to do the below operation on the list qs.

FormQuestions fq;
fq.getFormsId();

How can I perform the above operation from the list?

I'm a beginner to java spring, any help will be considered a big help.

Upvotes: 1

Views: 72

Answers (1)

kidney
kidney

Reputation: 3083

Assuming getFormsId is a getter (as you state in the comments):

qs.stream().map(fq -> fq.getFormsId()).collect(Collectors.toList());

will get you a list of whatever getFormsId returns from each of the FormQuestions.

Upvotes: 1

Related Questions