Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7711413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:22:09+00:00 2026-06-01T01:22:09+00:00

hi I am new here and new in Java programming as well actually my

  • 0

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

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<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";
        } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:22:10+00:00Added an answer on June 1, 2026 at 1:22 am

    You can use a for-each loop, and check for each element if it is borrowed [assuming Book has a method onLoanStatus() which indicate if it is on load or not]

    Should look something like that:

    int count = 0;
    for (Book b : booksHeld) { 
      if (b.getOnLoanStatus()) count++;
    }
    //now count holds the number of loaned books.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new here and kinda new to java. I've encountered a problem. I have
I'm new here to stackoverflow, so bear with me. I have a book that
am new here. i have a slight problem; PLease look at the following code
I'm writing (well, completing) an extension of Java which will help role programming. I
I'm trying out several exercises from a Java programming book. I have the code
Let me start by saying, I am new to Java programming. I have coded
I'm kind of stumped here. I'm relatively new to Java/Programming in general. I want
I'm fairly new to programming in general but have been working with Java for
Hey everyone! I am new to blackberry programming although I do have some java
I'm fairly new to Android programming and to Java in general, but I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.