Positively and simply, get(int index) returns the element at the specified index.
So we have an ArrayList of String :
List<String> names = new ArrayList<String>(); names.add("Arthur Dent"); names.add("Marvin"); names.add("Trillian"); names.add("Ford Prefect");
What can be visualized as:
Where 0, 1, 2, and 3 denote the ArrayList indices.
Let's say we wanted to get one of the names that we would make: String name = names.get(1); Which returns the name in index 1.
Therefore, if we printed the name System.out.println(name); The output would be Marvin .
Luke garrigan
source share