permaculture playing cards
The moose likes Beginning Java and the fly likes basic array-list method help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "basic array-list method help" Watch "basic array-list method help" New topic

basic array-list method help

Kevin Schweitz

Joined: May 17, 2011
Posts: 1
Hello all and thanks for the forum. I am trying to understand some basics for a class I am taking. I need to add a boolean method contains to my class called IntList which already has a bunch of other methods in it I created. All the method needs to do is return true if the parameter I am adding is already in my list and false if it isnt. I am passing in a list of integers from a file that is being scanned in to my test driver eventually if that helps. Not looking for an answer directly just someone to help me lay out the method. My book uses a while statement but in looking online I have found bits of pieces of if/else statements that are supposed to work as well.

Keep in mind I am barely learning the basics so basic level explanations would help me a lot. I am guessing but I am comparing ints not strings so I dont think I have to use compareto? Also I after I figure out what type of statement to write I need to look at my objects and values and figure where they go in the statement.
Greg Brannon

Joined: Oct 24, 2010
Posts: 563
The API is especially helpful to find answers to questions like this. The ArrayList API is here. Looking through the listed methods, you may find one that will help. For example, you may be able to use ArrayList.contains() to determine if the object you're testing for is contained in the subject ArrayList. contains() returns a boolean, so you may be able to use that result as the return from your method. Then again, if a method already exists that does what you want, why write a new one?

Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
I agree. Here's the link:
subject: basic array-list method help
It's not a secret anymore!