I'm confused about on how to use this array in a way that is simple. Well I already passed the values from the JSON into a List and now I need to retrieve it using a loop (and just loop) but I don't know how. Tried reading some answers but I found myself really confused in the end. I just want it to be simple as making a String array, loop and fetch data by getting the variable[index] simple as that but all the answers I've found just lead me into confusion. Help please.
List get() method in Java with Examples. The get() method of List interface in Java is used to get the element present in this list at a given specific index. Syntax : E get(int index) Where, E is the type of element maintained by this List container.
Many Java framework classes implement Iterable , however String does not. It makes sense to iterate over characters in a String , just as one can iterate over items in a regular array.
As I understand your question..
From Java List class you have to methods add(E e)
and get(int position)
.
add(E e)
Appends the specified element to the end of this list (optional operation).
get(int index)
Returns the element at the specified position in this list.
Example:
List<String> myString = new ArrayList<String>();
// How you add your data in string list
myString.add("Test 1");
myString.add("Test 2");
myString.add("Test 3");
myString.add("Test 4");
// retrieving data from string list array in for loop
for (int i=0;i < myString.size();i++)
{
Log.i("Value of element "+i,myString.get(i));
}
But efficient way to iterate thru loop
for (String value : myString)
{
Log.i("Value of element ",value);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With