Assuming your Car class has a getter method for price, you can simply use

System.out.println (car.get(i).getPrice());

where i is the index of the element.

You can also use

Car c = car.get(i);
System.out.println (c.getPrice());

You also need to return totalprice from your function if you need to store it

main

public static void processCar(ArrayList<Car> cars){
    int totalAmount=0;
    for (int i=0; i<cars.size(); i++){
        int totalprice= cars.get(i).computeCars ();
        totalAmount=+ totalprice; 
    }
}

And change the return type of your function

public int computeCars (){
    int  totalprice= price+tax;
    System.out.println (name + "\t" +totalprice+"\t"+year );
    return  totalprice; 
 }
Answer from Ankur on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › ArrayList.html
ArrayList (Java Platform SE 8 )
July 21, 2026 - The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation. Each ArrayList ...
🌐
W3Schools
w3schools.com › java › ref_arraylist_get.asp
Java ArrayList get() Method
The get() method returns the item at a specified position in the list.
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-get-method-java-examples
ArrayList get(index) Method in Java with Examples - GeeksforGeeks
July 22, 2026 - The get(int index) method of the ArrayList class is used to retrieve the element present at the specified index in the list.
🌐
W3Schools
w3schools.com › java › java_arraylist.asp
Java ArrayList
To access an element in the ArrayList, use the get() method and refer to the index number:
🌐
CodeHS
codehs.com › tutorial › 13901
Tutorial: ArrayLists in Java | CodeHS
Click on one of our programs below to get started coding in the sandbox! ... Learn how to create and use ArrayLists in your programs!
🌐
TutorialsPoint
tutorialspoint.com › java › util › arraylist_get.htm
Java ArrayList get() Method
The Java ArrayList get(int index) method returns the element at the specified position in this list. Index starts from 0 like first element can be retrieved using get(0) method call and so on.
Find elsewhere
🌐
Codecademy
codecademy.com › docs › java › arraylist › .get()
Java | ArrayList | .get() | Codecademy
February 1, 2023 - The .get() method retrieves the element at some index in an ArrayList.
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › util › ArrayList.html
ArrayList (Java SE 21 & JDK 21)
January 20, 2026 - Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument. ... Compares the specified object with this list for equality. ... Performs the given action for each element of the Iterable until all elements have been processed or the action throws an exception. ... Returns the element at the specified position in this list. ... Gets the first element of this collection.
🌐
Arnaudroger
arnaudroger.github.io › blog › 2018 › 06 › 01 › arraylist-vs-arrays.html
ArrayList.get(i) vs array[i]
June 1, 2018 - @Setup(Level.Invocation) public void nextIndex() { index = random.nextInt(size); } @Benchmark public Long testGet() { return data.get(index); } ... In the following result, you can see a 10% penalty for using ArrayList, and a massive 160% difference for a 1 million elements array, which is pretty suspicious.
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-arraylist-get-method-example
Java ArrayList get() Method example
March 21, 2016 - ArrayList get(int index) method is used for fetching an element from the list. We need to specify the index and get method returns the value present at the specified index.
Top answer
1 of 3
23

Arrays are laid sequentially in memory. This means, if it is an array of integers that uses 4 bytes each, and starts at memory address 1000, next element will be at 1004, and next at 1008, and so forth. Thus, if I want the element at position 20 in my array, the code in get() will have to compute:

1000 + 20 * 4 = 1080

to have the exact memory address of the element. Well, RAM memory got their name of Random Access Memory because they are built in such way that they have a hierarchy of hardware multiplexers that allow them to access any stored memory unit (byte?) in constant time, given the address.

Thus, two simple arithmetic operations and one access to RAM is said to be O(1).

2 of 3
14

Posted as answer, as suggested:

ArrayList.get(int) does not search. It returns directly the element addressed by the index supplied... Exactly like with an array - hence the name.

ArrayList.get(int) source:

public E get(int index) {
    rangeCheck(index);

    return elementData(index);
}

Where rangeCheck(int) is:

private void rangeCheck(int index) {
    if (index >= size)
        throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
}

And elementData() is:

E elementData(int index) {
    return (E) elementData[index];
}

A Linked List would however have an O(n) get: it would have to step to the next element until the desired index is reached...

public E get(int index) {
    return entry(index).element;
}

Where entry(int) is (this is what makes it O(n)):

private Entry<E> More ...entry(int index) {
    if (index < 0 || index >= size)
        throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);

    Entry<E> e = header;

    if (index < (size >> 1)) {
        for (int i = 0; i <= index; i++)
            e = e.next;
    } else {
        for (int i = size; i > index; i--)
            e = e.previous;
    }
    return e;
}

(Note: it is double linked list, so saves some time by selecting the endpoint that is closest to the desired result, but this is still O(n) )

🌐
Programiz
programiz.com › java-programming › library › arraylist › get
Java ArrayList get()
Here, arraylist is an object of the ArrayList class. The get() method takes single parameter.
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-in-java
ArrayList in Java - GeeksforGeeks
Automatic Resizing: When the internal array becomes full, the ArrayList automatically increases its capacity by creating a new larger array and copying the existing elements into it. Index-Based Access: Elements are stored in contiguous memory locations, allowing fast access using indexes (e.g., get(index)), typically in O(1) time complexity.
Published: May 12, 2026
🌐
Vultr
docs.vultr.com › java › standard-library › java › util › ArrayList › get
Java ArrayList get() - Retrieve Element | Vultr Docs
September 27, 2024 - Use a for loop with the get() method to iterate through all elements of an ArrayList.