• Post Reply Bookmark Topic Watch Topic
  • New Topic

Android Data Structures?  RSS feed

 
Pete Letkeman
Ranch Foreman
Posts: 853
25
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This thread https://coderanch.com/t/685907/java/data-structure lead me here with the following post.
Many of the Android database/SQLite tutorials that I've seen thus far suggest doing either a select to return one single object or a select to return many objects.
The single object data structure seems fairly straight forward, use a POJO.
The many objects data structure tutorials, which I've come across suggest ArrayList.

From what I've gathered most/all of Java 7 can be used with Android development as well has much of Java 8.
I also realize that each case is different.
With all of that being said is it fairly safe to say that ArrayLists do a fairly decent job for Android when retrieving many (>100)  records from a database?

Would you say that the reason that ArrayLists are used because they are easier to work with or understand or efficient then other collection classes e.g. LinkedList, HashMap, etc

Given this person class:

What collection class(es) would you recommend for use in Android assuming that at most there would be 500 possible objects returned, using a pagination mechanism?
 
Tim Cooke
Marshal
Posts: 3968
234
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Often you have to ask yourself: "Do I really need 100s or 1000s of records?". Are you presenting that to the UI and expecting the user to consume all of it? In practice that rarely happens so why do it?

This is not unique to Android development of course.
 
Pete Letkeman
Ranch Foreman
Posts: 853
25
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Cooke wrote:Often you have to ask yourself: "Do I really need 100s or 1000s of records?"

While that is correct, I was thinking of allowing people to view their workout history whenever I get around to creating the workout app and corresponding web site.
Sure people will be able to use a web browser to view the history and do more.

Yet I still would like to know if ArrayList would be the most efficient collection class to use.
I also know from reading posts on this site that efficiency may not be the best way to design/program when starting out.
Only if there is a noticeable delay or memory use would it be wise to rethink for efficiency.

I know that my problems include:
  • I don't know enough about the collection classes
  • I don't know enough about the map classes
  • I don't know enough about Android development
  •  
    Paul Clapham
    Sheriff
    Posts: 22722
    43
    Eclipse IDE Firefox Browser MySQL Database
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    When I want a list of things in Java I always use an ArrayList. That's just a default choice because it's good enough, and generally I'm only using the list of things as a tool to transfer data from, say, a database to a GUI component. I wouldn't use a Map unless I needed a structure with keys and values, and I wouldn't bother with any other kind of List unless I planned to do some (a lot of) manipulations for which that other kind of List is supposed to be better. Like, supposedly a LinkedList is better if you want to insert entries in the middle of the list. Android would be the same, I'm pretty sure.
     
    Pete Letkeman
    Ranch Foreman
    Posts: 853
    25
    Android Chrome IntelliJ IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you very much Paul.
    That does clear things up for me substantially.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!