Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJohn Fowler
7,913 Pointsarray list methods
Why are array list methods returning boolean values? for example, why does fruit.add("apple"); return true?
2 Answers
Benjamin Barslev Nielsen
18,958 PointsAn ArrayList implements the interface List, which defines the method signature for a lot of ArrayList's methods, which means that it is the interface List that specifies that the add method should return a boolean. The reason that it makes sense to return a boolean, is to indicate if the item actually was added to the list. Some lists might have some limitations as to which elements you can add, and therefore they can return false to indicate that the element was not added to the list. In your example it simply means that "apple" was successfully added to the list.
John Fowler
7,913 PointsThanks, that makes sense that the question would be "did it add to the list?"