Skip to content
Advertisement

How to use ArrayList get() method in Android Studio

I made a code using an ArrayList (short[]) in Android Studio but when I use the get() method it always return the last data stored and I don’t know why. I’m using two buttons, one execute adquirir_audio() just to store some values. The second one prints in the console the stored data using a for loop, but it always return the same values.

Here is the code:

JavaScript

And here is the console

enter image description here Hope you can help me.

Advertisement

Answer

In java the Arrays are not a primitive type and you are always changing the same buffer_debug object in all elements of the ArrayList.

You can use something like:

JavaScript
Advertisement