O'Reilly logo

Java Programming for Beginners by Mark Lassoff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Giving control to the user

ArrayLists have a lot of power contained within them. We can turn them into arrays, create them from arrays, and all sorts of things. If we go to the Java documentation and check under java.util for ArrayList, we can find all of their methodologies. Let's add few more features to our ArrayList program so that I can walk you through some common ArrayList methods.

ArrayLists have a function that takes no input, called clear(), which will erase our ArrayList. We can utilize this function to give our users some control over our program. Let's say that if the user inputs the string CLEAR, we would like to erase all of the information in our ArrayList. Well, that's a conditional statement I just made, so we use an if ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required