The method get(int index) is used to retrieve the element at a specific index in an array or list.
Think of an array or list as a vending machine with numbered slots. When you use the get() method, it's like pressing a button to retrieve the item from a specific slot.
ArrayIndexOutOfBoundsException: This exception occurs when you try to access an invalid index that is outside the bounds of an array.
IndexOutOfBoundsException: Similar to ArrayIndexOutOfBoundsException, this exception occurs when you try to access an invalid index that is outside the bounds of a collection or list.
set(int index, E element): This method is used to replace the element at a specific index in an array or list with a new element.
Study guides for the entire semester
200k practice questions
Glossary of 50k key terms - memorize important vocab
© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.