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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:16:38+00:00 2026-06-15T15:16:38+00:00

First example int windowStart = 0; for (int i = 0; i + windowSize

  • 0

First example

int windowStart = 0;

for (int i = 0; i + windowSize < fileArray.size(); i++) {
  ArrayList <Character> window = new ArrayList <Character> ();
  for (int s = windowStart; s <= windowStart + windowSize; s++) {
    window.add(fileArray.get(s));
  }
  windowStart++;
}

VS.

second example

int ind = 0;
for (int i = 0; i + windowSize < fileArray.size(); i++) {
  for (int b = ind; b <= windowSize + ind; b++) {
    window.add(fileArray.get(b));
  }
  ind++;
}

The first one throws an java.lang.IndexOutOfBoundsException while the second one does not and works just fine. fileArray is the same for both, but for 2. the window array is defined as an attribute, while for the first one, the “window” array is defined inside the method (and the for loop). Does that make a difference?

  • 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-15T15:16:40+00:00Added an answer on June 15, 2026 at 3:16 pm

    You can’t get an IndexOutOfBoundsException for adding a value to a list. The problem is that a value of s is equal or greater then the actual size of the fileArray array or list.

    And because the loops in both examples are equivalent, the problem should be found outside the lines of code you’ve just posted.

    Try to debug (break on IndexOutOfBoundsException if you are using an IDE, otherwise add some simple System.out.println statements to find out, why s is greater than expected.

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

Sidebar

Related Questions

In the first example of Boost, in(std::cin) is used. I think in() get an
First example: struct State { SomeLargeObjectThatTakesTimeToCopy obj; int x; } myState; auto f =
Take this example: int[] queryValues1 = new int[10] {0,1,2,3,4,5,6,7,8,9}; int[] queryValues2 = new int[100];
First example which works: public class Test { public int ID; public string Name;
When attempting to run the first example in the boost::mpi tutorial , I was
Assume methods M1 and M2 have strongly related responsibilities First example: If • M1
I have a simple marker annotation for methods (similar to the first example in
If I have three files index.php file.php and fns.php First example (it works): index.php
Could someone explain this (strange) behavior? Why is the length in the first example
I am learning ADO.NET entity framework. This is my first example. The datagrid seems

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.