How to add SQLite rows to an ArrayList<>
- Android Development
- 2 Replies
Assuming you want to create an Array of Strings, as you've declared
then just write
Assuming TableClass.Name_Column is a string value.
If you want to create an ArrayList containing objects corresponding to the rows in your database table, then you'll have to create a class that represents all the data fields in that table. E.g.
then create Person objects using rows retrieved from the database, and declare an ArrayList like this
Code:
ArrayList<String> info
then just write
Code:
info.add(check.getString(check.getColumnIndex(TableClass.Name_Column))
Assuming TableClass.Name_Column is a string value.
If you want to create an ArrayList containing objects corresponding to the rows in your database table, then you'll have to create a class that represents all the data fields in that table. E.g.
Code:
class Person {
private String firstName;
private String surName;
private Integer age;
}
then create Person objects using rows retrieved from the database, and declare an ArrayList like this
Code:
ArrayList<Person> people = new ArrayList<>;
Good luck and have fun with your new toy!