So what is the difference between the following codes in a standard for loop: list.get(i) //I know this holds the current element in the list. list.get(i+1); list.get(i -1) list.get(i) + 1) //I think this one grabs the next element following the current element???? list.get(i) -1) I am a little confused as to how this works...or how to implement it. Thanks.
So what is the difference between the following codes in a standard for loop?
You must be signed in to leave a comment
8 February 2021, 10:03
8 February 2021, 19:19
Thank you so much, it makes more sense now that you explained it. So just to make sure I got it... (list.get(i) + 1); this adds 1 to the value of i. (example if i= 4 ) return will be 5. list.get((i) + 1); this code gets the next element from current one. (example: 4 5 6 8 9) if current element is at 6, the previous code will return 8. right?
9 February 2021, 08:58
(list.get(i) + 1); this adds 1 to the value of i. (example if i= 4 ) return will be 5. I'd say it get's the value at index i in the list and adds 1 to that value. Why not have a live example. That makes everything much clearer ;)
9 February 2021, 16:39
Sweet! Live examples are awesome and always welcome. thank you for your time. :)