Win a copy of Microservices in Action this week in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Android Data Structures?  RSS feed

 
Bartender
Posts: 1867
81
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?
 
Sheriff
Posts: 4578
286
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
Bartender
Posts: 1867
81
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
  •  
    Sheriff
    Posts: 23889
    50
    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
    Bartender
    Posts: 1867
    81
    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.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!