d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Explain The Difference Plz
Add Reply New Topic New Poll
Member
Posts: 31,293
Joined: Mar 25 2009
Gold: 0.00
Jan 20 2019 01:37am
What is the difference between these 2 lines of code?

boolean exists = groceryList.contains(searchItem);


int position = groceryList.indexOf(searchItem);






^groceryList is a class... using an arrayList:
private ArrayList<String> groceryList = new ArrayList<String>();
Member
Posts: 9,432
Joined: Aug 13 2007
Gold: 20.00
Jan 20 2019 09:52pm
1st one returns true or false if searchItem is contained in the array or not

2nd one returns the location (index) of searchItem in the array
Member
Posts: 31,293
Joined: Mar 25 2009
Gold: 0.00
Jan 20 2019 10:27pm
Quote (EViLDeeDz @ Jan 20 2019 11:52pm)
1st one returns true or false if searchItem is contained in the array or not

2nd one returns the location (index) of searchItem in the array


thanks!!
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll