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

  • SEARCH
  • Home
  • 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 7789783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:24:09+00:00 2026-06-01T21:24:09+00:00

okay not sure if there is a better way than I’m already doing. Right

  • 0

okay not sure if there is a better way than I’m already doing. Right now I have a list(int[]) that has a over 10,000 values that equal 0 in it and I’m looking for only the non-zero items.

My current approach is just to do a for loop and capture all the non-zeros but I do this a lot, and profiling shows its taking a large amount of my cpu time(since I’m doing this so often). Is there a way I can get the same results without the expensive cpu process(since out 10,000 items, only less than 100 will be non-zeros)?

Here’s an example of my data:

int[] list = {0,0,0,1,0,10 }
int[] list_names = {a,b,c,d,e,f}

All I need to ultimately do is use these two lists to create another two lists with only the non-zero values and their names(so D=1 and F=10). I’ve seen some solutions where I need to sort the results before it works but thats a problem because if I sort the data list then I cannot identify its name.

Is this possible and is there a faster way compared to a for loop?

Sorry I should mention that this large lists remain in my program for processing and I’m trying to do this to reduce the memory footprint of them. I have a queue of a few hundred million of these lists being stored in their entirety when all I really need is the non-zero values, so doing this to save memory(which seems to be working) but I’m also trying not to take a bit hit on the cpu to get it to that point(since I need the cpu for my processing).

  • 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-06-01T21:24:10+00:00Added an answer on June 1, 2026 at 9:24 pm

    If you don’t know anything else about the array, then you’re going to have to look at every value. That means that looping over the whole array is basically the best you can hope for. If it’s sorted, or if you know some other information about it, that might help — but otherwise, there are no alternatives.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay - I'm not even sure that the term is right - and I'm
Okay, I'm not sure if there's a duplicate, because I can't think of a
Okay, so not sure if apple.stackexchange is a better place for this, but I
Okay so I am not sure if a lot of you have started to
I'm not sure what's going on, but on my own laptop, everything works okay.
Okay, I feel totally stupid posting this. I am not sure if it is
Okay I'm looking for some input, I'm pretty sure this is not currently supported
Okay, im not going to piddle foot around and dance around what im doing.
Okay, so I have been searching and searching and have not found any help.
Okay I have updated my code a little, but I am still not exactly

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.