title: With Thymeleaf how do I display an iteration through an arraylist?
body: <p>In my controller I have a loop that iterates through an arraylist and displays the attributes belonging to each object in the arraylist and I am wondering what should I put in my thymeleaf code because at the moment it is only displaying the information of the first object in the arraylist. </p>
  
  <p>My Controller class</p>
  
  <pre><code>   @GetMapping("/allSubjects")
  public String shoSubjects(@ModelAttribute("subject") @Valid UserRegistrationDto userDto, BindingResult result, Model model) {
      Authentication loggedInUser = SecurityContextHolder.getContext().getAuthentication();
      String email = loggedInUser.getName();   
  
      User user = userRepository.findByEmailAddress(email);
  
      ArrayList&lt;String&gt; subjects = new ArrayList&lt;String&gt;();
  
      for(Subject sub:user.getSubject())
      {
          subjects.add(sub.getSubjectName());
      }
      model.addAttribute("subjects", subjects);
  
  
      if(!subjects.isEmpty()) {
  
      for(int i = 0; i&lt;subjects.size(); i++) {
  
              String subjectName = (subjects.get(i));
              Subject subject = subjectRepository.findBySubjectName(subjectName);
  
              String subjectName1 = subject.getSubjectName();
              Double subjectGradeGoal = subject.getSubjectGradeGoal();
              Double caCompletedWorth = subject.getCaCompletedWorth();
              Double subjectResults = subject.getSubjectResults();
              Double maxSubRemMarks = subject.getMaxSubRemMarks();
              Double marksNeededToReachGoal = subject.getMarksNeededToReachGoal();
              Boolean isGoalPossible = subject.getIsGoalPossible();
              Double highestPossibleGrade = subject.getHighestPossibleGrade();
  
              model.addAttribute("subjectName",subjectName1);
              model.addAttribute("subjectGradeGoal",subjectGradeGoal);
              model.addAttribute("caCompletedWorth",caCompletedWorth);
              model.addAttribute("subjectResults",subjectResults);
              model.addAttribute("maxSubRemMarks",maxSubRemMarks);
              model.addAttribute("marksNeededToReachGoal",marksNeededToReachGoal);
              model.addAttribute("isGoalPossible",isGoalPossible);
              model.addAttribute("highestPossibleGrade",highestPossibleGrade);
              return "allSubjects";
  
          }
  
  
      }
  
  return "allSubjects";
  
  }
  </code></pre>
  
  <p>My html class</p>
  
  <pre><code>  &lt;&gt;Subject: &lt;h4 th:text="${subjectName}" /&gt; &lt;/&gt; 
  </code></pre>
  
  <p>//I have this for each attribute I have just not added it in for this post.</p>