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 8358067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:41:00+00:00 2026-06-09T10:41:00+00:00

I have an ArrayList of Strings, size of which may vary. List<String> strList1 =

  • 0

I have an ArrayList of Strings, size of which may vary.

List<String> strList1 = new ArrayList<String>();

For each of the Strings, I am calling a method updateDetails(strList1), which processes it and prints an op based on some logic.

I would like to call the above method updateDetails(strList1) for the first string, then for 5 (including first 1) etc in fixed intervals as below

The intervals are 1, 5, 10, 50, 100, 200, 1000

The o/p (if strList1 size is 25) should be something like:

Result for first 1:
Result for first 5:..
Result for first 10:..
Result for total 25 : 

The o/p (if strList1 size is 9) should be something like:

Result for first 1:..
Result for first 5:..
Result for total 9:..

How to go about it?

  • 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-09T10:41:01+00:00Added an answer on June 9, 2026 at 10:41 am

    You can avoid duplicates with

    int len = strList1.size();
    NavigableSet<Integer> sizes = new TreeSet<>();
    sizes.addAll(Arrays.asList(1, 5, 10, 50, 100, 200, 1000, len));
    for(int size: sizes.lower(len+1)) {
        List<String> list2 = strList1.subList(0, size);
        // process list2
    }
    

    If duplicates are not a problem.

    int len = strList1.size();
    for(int size: new int[] { 1, 5, 10, 50, 100, 200, 1000, len }) {
        if(size > len) continue;
        List<String> list2 = strList1.subList(0, size);
        // process list2
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

E.G. to create an ArrayList of Strings we have to do something like List<String>
i have an arraylist of strings in my servlet which im passing forwarding using
I have an ArrayList of strings, and I want to randomly change a string's
I have an ArrayList of HashMap like this: ArrayList<HashMap<String, String>> playListSongs = new ArrayList<HashMap<String,
I have the following ArrayList ArrayList<HashMap<String, String>> list; HashMap<String, String> map; with the following
i have this code: ArrayList list = new ArrayList(); foreach (DataRow dataR in prenume.Rows)
Problem: I have a method that creates a list from the parsed ArrayList. I
List<String> flowers = new ArrayList<String>(); My for loop currently looks like this... for (int
I have a List of List<String> 's which I get from a external API
I have an array list ArrayList<String> firstname; In this I am storing n number

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.