简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM