Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6924453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:39:55+00:00 2026-05-27T10:39:55+00:00

Try to focus on general dos and donts regarding lists, e.g. is adding and

  • 0

Try to focus on general “dos and donts” regarding lists, e.g. is
adding and removing 30 items of a 200 item list better then clearing
and repopulating? Or any other tips in this area – I cant really try
on my phone, to fast for that 🙂

Is there any way to calculate the memory overhead / calculation power of list operations. The background is as following:

I have a list view on a page, the page has e.g. 3 Tabs at the bottom (All, Search, Recent). Now if you click on a tab, the listview should show you the approriate items.

There are two different approaches now, one is:

Use a single ListAdapter, filter the items accordingly
– If you click All, just put all items from the DB into it
– If you click Recent, just put the items which meet the requirements

Use two (three..) ListAdapters, one for each category
– If you click All, setAdapter() of list to the approriate one
– If you click Recent, setAdapter() to appropriate one

We are talking about a list of 200 items, which are complex objects created out of a database. When e.g. searching for an item, you enter part of the title, and the list should only show the appropriate items. The items will not be recreated, I would query for the IDs only, and use the buffered items (see later on datastructure).

What I am also not sure about is “where to filter”, I could do it in the database (select from where title LIKE abc) and then EITHER:

  • remove not matching items from the list and add all matching (but not included) items
  • clear the whole list, add all matching items

Again, to clarify the structure of the App data:

  • Database with raw simple entries (with IDs + title + …)
  • HashSet with complex entries, created once from DB, readonly + always all entries
  • ArrayList of current entries shown in a listView

I hope you get my drift, I am trying to get a feel for “expensive” operations. Perhaps, as a last motivation to answer, I will write some cases down, and you can give an opinion about how costly they are:

  1. Selecting N items (ID only) from DB with “title LIKE”
  2. Iterating a list of 200 items with a “title.contains()” and using only matches
  3. Removing 100 items from an arraylist SHOWN by an list view
  4. Removing 100 items from an arraylist not shown, then connect and show

Thanks for any feedback, or any tips for bad practices. Especially possible event trigger problems by working on visible list elements, instead of doing it first “in the background” and then setting a new ListAdapter

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:39:55+00:00Added an answer on May 27, 2026 at 10:39 am

    I see you have accepted an answer already, but I think I don’t agree, because ArrayList has to copy all elements, if in the middle is an element added or removed.

    I understand you already have a HashSet with all entries.

    In that case, I believe the most efficient adapter is a custom ListAdapter inspired from ArrayAdapter

    • your adapter stores an ArrayList mAllObjects of all entries (for the “all” tab).
    • your adapter stores an ArrayList mRecentObject of recent entries (for the “recent” tab)
    • your adapter stores an ArrayList mMatchObject of matching entries (for the “search” tab)
    • your adapter has two filters
      • the recent filter returns the mRecentObject list (and creates it if it does not exist already)
      • the match filter creates a new mMatchObject list and adds matching elements. There is no optimization to be done here. the delete()method on an ArrayList is O(n).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Try the following code public enum Color { Blue=1, Red=2, Green=3 } public List<Color>
Try to see which cast is faster (not necessary better): new c++ case or
If I have problems with WPF, then it always concerns the Focus-Management. There are
try: F2 start editing and ENTER stop editing and the focus switches to the
So I try: <html> <head> </head> <body> <script> window.onblur = function() { window.focus(); };
Here is my code: jQuery('span.con').delegate('input#sdate', 'focus', function(e){ try { var oneDay = 24*60*60*1000; rangeConv
I am trying to use focus event on list element. it's working with hover,
I need to focus out from the textbox when it focus in. I try
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
try { ... } catch (SQLException sqle) { String theError = (sqle).getSQLState(); ... }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.