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.
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?
Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795