• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Android Data Structures?

 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  •  
    Marshal
    Posts: 28263
    95
    Eclipse IDE Firefox Browser MySQL Database
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Bartender
    Posts: 1868
    81
    Android IntelliJ IDE MySQL Database Chrome Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you very much Paul.
    That does clear things up for me substantially.
     
    It was the best of times. It was the worst of times. It was a tiny ad.
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic