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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:09:51+00:00 2026-05-25T18:09:51+00:00

I have a for loop in which i test for the size of a

  • 0

I have a for loop in which i test for the size of a list.

for(int i = 0; i< thumbLinks.size(); i++) {
                        Log.e("URL" + i, thumbLinks.get(i));




                 url0 = thumbLinks.get(i);
                 url1 = thumbLinks.get(i); 

                 //Fix index out of bounds exception
                 url2 = thumbLinks.get(i);



              }

When i is added each time as you can see i am asking for i 3 times to get 3 urls. Since i am unsure about how many URL’s i will have. I use i to increase.
The correct output i want is for

    url0 = thumbLinks.get(i);// which is support to be equivalent to 1
    url1 = thunkLinks.get(i);//which is suppose to be equivalent to 2

and so on..

But my code doesnt do this…

It just adds 1 each time to each url.
How can i fix this
?

  • 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-25T18:09:51+00:00Added an answer on May 25, 2026 at 6:09 pm

    EDIT: Okay, so it sounds like you really only want to deal with up to three URLs. So you want something like:

    String url0 = thumbLinks.size() > 0 ? thumbLinks.get(0) : null;
    String url1 = thumbLinks.size() > 1 ? thumbLinks.get(1) : null;
    String url2 = thumbLinks.size() > 2 ? thumbLinks.get(2) : null;
    
    // Use url0, url1 and url2 where any or all of them may be null
    

    EDIT: I’m assuming you want to deal with the URLs in batches of three for some reason. If that’s not the case, it’s not clear what you are trying to do.

    Your code isn’t clear – you’re not incrementing i between calls to thumbLinks.get(i) – but I suspect you want something like:

    if (thumbLinks.size() % 3 != 0) {
       // What do you want to do if it's not a multiple of three?
       throw new IllegalArgumentException(...);
    }
    for (int i = 0; i < thumbLinks.size(); i += 3) {
        String url0 = thumbLinks.get(i);
        String url1 = thumbLinks.get(i + 1);
        String url2 = thumbLinks.get(i + 2);
        // Use url0, url1 and url2
    }
    

    Or:

    int i;
    for (i = 0; i < thumbLinks.size() - 2; i += 3) {
        String url0 = thumbLinks.get(i);
        String url1 = thumbLinks.get(i + 1);
        String url2 = thumbLinks.get(i + 2);
        // Use url0, url1 and url2
    }
    for (; i < thumbLinks.size(); i++) {
      // Deal with the trailing URLs here, one at a time...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In function verify, I have a loop called size which is identical to the
I have a loop which basically calls this every few seconds (after the timeout):
I have a loop which needs to create an unspecified and indefinite amount of
I have a loop MC which will be duplicate to stage several times according
I have a for-loop which performs the following function: Take a M by 8
i have a php loop which displays only one record even if there is
I have the following loop which is giving me problems $(#divResults).append('<table>'); $.each( results.d, function(
I have a binary search loop which gets hit many times in the execution
In my code, I have this loop, which brings up various 2-hour time blocks.
I have a for loop, inside which I'm calling a method to show the

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.