Predicate Methods

Another common use for accessor methods is to test whether a condition is true or false—such methods are often called predicate methods. An example would be class ArrayList’s isEmpty method, which returns true if the ArrayList is empty and false otherwise. A program might test isEmpty before attempting to read another item from an ArrayList.

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.