☰
d2jsp
Rules
Help
Forum Gold FAQ
Live Streams
Photo Gallery
Hourly Raffle
Ladder Slasher
Log In
Register
Log In
Register
Account Recovery
Resend Validation Email
d2jsp Forums
>
Off-Topic
>
Computers & IT
>
Programming & Development
> Explain The Difference Plz
Add Reply
New Topic
New Poll
Views: 376
Replies: 2
Track Topic
ferf
Member
Posts: 31,293
Joined: Mar 25 2009
Gold
:
0.00
#1
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>();
EViLDeeDz
Member
Posts: 9,432
Joined: Aug 13 2007
Gold
:
20.00
#2
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
ferf
Member
Posts: 31,293
Joined: Mar 25 2009
Gold
:
0.00
#3
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
© 2003-2024 d2jsp
Contact