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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:14:26+00:00 2026-06-14T03:14:26+00:00

Exception in thread main java.lang.IndexOutOfBoundsException: Index: 175, Size: 175 at java.util.ArrayList.rangeCheck(Unknown Source) at java.util.ArrayList.remove(Unknown

  • 0
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 175, Size: 175
    at java.util.ArrayList.rangeCheck(Unknown Source)
    at java.util.ArrayList.remove(Unknown Source)
    at GetData.main(GetData.java:42)

That’s the exception that I get on my list l, but when I call l.size(), it returns 188!

Here’s a SSCCE (well, as concise as I can make it):

import java.io.*;
import java.util.*;
import java.util.regex.*;


public class GetData {
    @SuppressWarnings("unchecked")
    public static void main(String[] args) throws Exception {
        //optimize();
        BufferedReader r = new BufferedReader(new FileReader(new File("countrydata - optimized.txt")));
        String str = "";
        String line = null;
        int x = 0;
        while ((line = r.readLine()) != null) {
            str += line;
            x ++;
            if (x % 20 == 0) System.out.println("Reading file... // " + x / 20 + " of 18");
        }
        Pattern p = Pattern.compile("<strong>(.*?)</strong><br/>(.*?)<");
        Matcher m = p.matcher(str);
        //PrintWriter w = new PrintWriter(new BufferedWriter(new FileWriter(new File("countrydata - verbose.xml"))));
        //w.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        ArrayList<HashMap<String, String>> l = new ArrayList<>(188); //This is one ugly line of code right here
        HashMap<String, String> a = null;
        String[] countries = "Afghanistan/Albania/Andorra/Angola/Antigua and Barbuda/Antigua and Barbuda 2/Argentina/Argentina 2/Australia/Astria/Azerbaijan/Bahamas/Bahrain/Bangladesh/Barbados/Barbados 2/Belgium/Belize/Benin/Bhutan/Bolivia/Bosnia and Herzegovina/Botswana/Brazil/Brunei/Bulgaria/Burkina Faso/Burundi/Cambodia/Cameroon/Canada/Cape Verde/Central African Republic/Chad/Chile/China/Colombia/Comoro Islands/Congo/Costa Rica/Cote d'Ivoire/Croatia/Cuba/Cyprus/Czech Republic/Denmark/Djibouti/Dominica/Dominican Republic/Dominican Republic 2/Ecuador/El Salvador/El Salvador 2/Eritrea/Estonia/Ethiopia/Fiji/Finland/French/Gabon/Gambia/Georgia/Germany/Ghana/Greece/Greece 2/Grenada/Guatemala/Guinea/Guinia-Bissau/Guyana/Haiti/Honduras/Hungary/Iceland/India/Indonesia/Iran/Iraq/Ireland/Israel/Italy/Jamaica/Jamaica 2/Jordan/Kazahkstan/Kenya/Kiribati/Kuwait/Kyrgyzstan/Laos/Latvia/Lebanon/Lebanon 2/Lesotho/Libya/Liechtenstein/Lithuania/Luxembourg/Macedonia/Madagascar/Malawi/Malaysia/Maldives/Mali/Mali 2/Malta/Mauritania/Mexico/Moldova/Monaco/Mongolia/Morocco/Mozambique/Myanmar/Namibia/Nepal/New Zealand/Nicaragua/Niger/North Korea/Norway/Oman/Oman 2/Panama/Papua New Guinea/Prarguay/Peru/Phillippines/Poland/Portugal/Qatar/Romania/Russia/Russia 2/St. Kitts and Nevis/St. Lucia/St. Vincent and the Grenedines/San Marino/Sao Tome and Principe/Saudi Arabia/Senegal/Seychelles/Sierra Leone/Singapore/Slovakia/Slovenia/Soloman Islands/Somalia/South Africa/South Korea/Spain/Spain 2/Sudan/Suriname/Swaziland/Sweden/Switzerland/Switzerland 2/Tawian/Tajikistan/Tanzania/Thailand/Togo/Tonga/Trinidad & Tobago/Tunisia/Turkey/Turkmenistan/Tuvalu/Uganda/Ukraine/United Arab Emirates/United Kingdom/United States/United States 2/Marshall Islands/Micronesia/Uruguay/Uzbekistan/Vanuatu/Vietnam/Samoa/Yemen/Zimbabwe/East Timor/???/Serbia".split("/");
        int ci = 0;
        while (true) {
            if (m.find()) {
                //System.out.println((m.group(1).equals("Internet Users") ? "NEW COUNTRY\nInternet Users" : m.group(1)) + "|" + m.group(2));
                if (m.group(1).equals("Internet Users")) {
                    if (a != null) l.add(a);
                    if (ci == 188) break;
                    a = new HashMap<String, String>();
                    a.put("Country Name", countries[ci++]);
                    a.put("Internet Users", m.group(2));
                } else {
                    a.put(m.group(1), m.group(2));
                }
            } else break;
        }
        for (int i = 0; i < countries.length; i ++) {
            if (countries[i].matches(".*2")) l.remove(i);
        }
        String[] data = "".split("\\.");
        for (Object map : l.toArray()) {
            a = (HashMap<String, String>) (map);
            System.out.println(a.get("School System"));
            System.out.println(a.get("Country Name"));
        }
        r.close();
    }

The file countrydata - optimized is just a bunch of lines of data in the form <strong>(name of data)</strong><br/>(the data)<div id="..., but that’s probably not important for this problem.

Why does l.size() return 188 when the exception says it has a size of 175?

  • 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-14T03:14:27+00:00Added an answer on June 14, 2026 at 3:14 am
    ArrayList<HashMap<String, String>> l = new ArrayList<>(188);
    

    188 is the initial capacity of the list, not it’s size.

    You are not making sure, that i doesn’t exceed the size of the list in the following:

    for (int i = 0; i < countries.length; i ++) {
        if (countries[i].matches(".*2")) l.remove(i);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting the following error: Exception in thread main java.lang.IndexOutOfBoundsException: Index: 86, Size: 86
Exception in thread main java.lang.NullPointerException at java.io.Reader.<init>(Unknown Source) at java.io.InputStreamReader.<init>(Unknown Source) //at InputStreamReader inStream
Exception in thread main java.lang.ExceptionInInitializerError at org.apache.tools.ant.util.FileUtils.<clinit>(FileUtils.java:63) at org.apache.tools.ant.Project.<clinit>(Project.java:131) at Pv.plugin_execute(Pv.java:140) at Pv.main(Pv.java:194) Caused
Running Test.java throws error run: Exception in thread main java.lang.RuntimeException: Uncompilable source code -
Exception in thread main java.lang.NullPointerException at Library.loadBooks(Library.java:179) at UseLibrary.main(UseLibrary.java:105) This error makes me crazy!
if I run java -classpath ./sqljdbc4.jar myclassname error is Exception in thread main java.lang.NoClassDefFoundError:myclassname
I'm having a problem where I receive this error: Exception in thread main java.lang.NullPointerException
Error:Exception in thread main java.lang.NullPointerException at com.vipgamming.Frytree.Game.main(Game.java:47) I am not a very good programmer.
the program gives following exception: Exception in thread main java.lang.NullPointerException at myclasses.BubbleSort.run(BubbleSort.java:42) at acm.program.Program.runHook(Program.java:1519)
I get the following error: Exception in thread main java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.of([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet; at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableTypes(AltFormat.java:399) at

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.