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

  • SEARCH
  • Home
  • 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 8914609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:45:57+00:00 2026-06-15T04:45:57+00:00

i want to limit the arraylist to 50. but i dont know how. here’s

  • 0

i want to limit the arraylist to 50. but i dont know how.

here’s my code
Object1.java

public class Object1 {

    public String seat_no, id;


    public Object1(String seat_no, String id) {

        this.seat_no = seat_no;
        this.id = id;

    }
}

main.java

private ArrayList<Object1> list;

list = new ArrayList<Object1>();
  • 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-15T04:45:58+00:00Added an answer on June 15, 2026 at 4:45 am

    As tempting as it may sound, I’d advise against extending ArrayList or any other List implementation, because then you’ll be limiting yourself to using only one type of list. What happens if next time you want to limit a LinkedList and not an ArrayList? would you extend LinkedList too? what happens if you want to limit, basically, an arbitrary implementation of List?

    What you’re looking for already exists. You can use Commons Collections and wrap a list with a predicate:

    class SizePredicate implements Predicate {
        private List list;
        private int maxSize;
    
        public SizePredicate(List l, int size) {
            list = l;
            maxSize = size;
        }
    
        public boolean evaluate(Object obj) {
            if (list.size() >= maxSize) {
                throw new IllegalStateException("Your message here");
            }
            list.add(obj);
        }
    }
    
    ...
    
    List list = new LinkedList();  // Or, really, any implementation of list.
    
    List maxList = ListUtils.predicatedList(list, new SizePredicate(list, 50));
    

    Using the design above, you can use the same Predicate instance to limit any sort of list. You can also extend it to handle any sort of collection…

    … Without the need to extend any JDK class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to limit the no. of direct instance of a class( in Java)
Am having an arraylist and its code is: ArrayList<String> recentdata=new ArrayList<String>(); I want to
i just want limit a query by parameter inside a stored, but I get
hey, hi i want put limit on object creation means a class can have
I want to LIMIT Grouped results to 30, but instead I'm grouping all rows
I want to limit the number of instances of a class and I do
I want to limit number of chars in input text field. Code I'm using:
I want to limit a number between two values, I know that in PHP
I want to limit my users to a directory and its sub directories but
I want to limit the number of records returned by calling ROW_NUMBER(), but I

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.