how to get the count of number of true values in Arraylist java
<p>hi I am new here and new in Java programming as well actually my problem is that I have a Array List of type Book in which I am storing Book name and title and set the OnLoan value explicitly by true or false but I am able to store true or false value for the Book arrayList but I want to count number of true value in my arrayList say if 3 books having borrowed status true I want the count as 3 I dont know how to get that count out from ArrayList in java please help me out here is my sample code I am getting the true value by calling the getOnLoanStatus() from book class which holds true and false values</p>

<pre><code>int borrowCount=0;
     Book loanStatus = new Book();
     boolean l = loanStatus.getOnLoanStatus();
     //boolean to String conversion

     System.out.println("value of l is" + l);
     if(this.booksHeld.isEmpty()) 
      {
        return null;
      }
       for(int i=0;i&lt;this.booksHeld.size();i++)
       {
         if(booksHeld.contains(l)) // compare the isbn string with getIsbn Method
         {
             borrowCount++;
         }
       }
        if(borrowCount==0) 
        {
            return "Libray: " + numberOfBooks() + "books " +  " 0 book on Loan";
        }
        else
        {
          return "Libray: " + numberOfBooks() + "books " + borrowCount + "on Loan";
        } 
</code></pre>
