This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Android Data Structures?  RSS feed

 
Saloon Keeper
Posts: 1797
74
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?
 
Marshal
Posts: 4454
284
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
Saloon Keeper
Posts: 1797
74
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: 23640
    48
    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
    Saloon Keeper
    Posts: 1797
    74
    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.
     
    Don't get me started about those stupid light bulbs.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!