Loop through List in Android Studio

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Loop through List<Object> in Android Studio



I have a class called verse:


public class Verse {
String book;
int chapter;
int verse;
String contents;
}



Which is populated from a database into:



List<Object> list = new ArrayList<>();


List<Object> list = new ArrayList<>();



My question is how do I loop through the list and get each book, chapter and verse and contents?



I've tried:


for(int x=0; x < list.size(); x++) {
int book = list.get(x);
}



But I'm unsure what .get(x) is returning, and I have a feeling it might the entire row, but I dont know how to get the data out of it.


.get(x)



Can anyone help? I'm very new to android studio.





"I have a feeling it might the entire row". Well, if you're unsure what get(x) is returning it's unlikely any of us will know. so let's start here, why don't you print list.get(x) to the console and see what data you get.
– Aomine
6 mins ago




get(x)


list.get(x)





why do you have a List<Object> list = new ArrayList<>(); instead of List<Verse> list = new ArrayList<>(); ?
– Aomine
3 mins ago


List<Object> list = new ArrayList<>();


List<Verse> list = new ArrayList<>();




1 Answer
1



Overload the getters and setters or just make a getter a setter for each variable type.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results