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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:54:34+00:00 2026-05-31T17:54:34+00:00

Hi guys i catch exception: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0 Code look like this:

  • 0

Hi guys i catch exception:

java.lang.IndexOutOfBoundsException: Index: 1, Size: 0

Code look like this:

 **ArrayList decoded = new ArrayList(10);
        decoded.add(1, "A");**

I really don’t get it what’s wrong here ?

Maybe someone could help me on this.


Basically i want to do this:
I have chars for example likes this:

ABCEDFG

And array with numbers:

321211

I need to take first char and first number. char write into S arrayList:

S={"A"};

Look at number and again write same char in that position if number is 3 then in third place:
(If number 1 then just write it in arrayList)

S={"A","","","A"}

And delete number and char from arrayLists. Now they look like this:

BCEDFG

21211

and again the same till the end.

  • 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-31T17:54:35+00:00Added an answer on May 31, 2026 at 5:54 pm

    I suspect you’re confused between capacity and size. This line:

    ArrayList decoded = new ArrayList(10);
    

    … creates a list with a capacity of 10 (it won’t need to grow internally until the eleventh element is added), but a size of 0. The only index you can add anything is 0.

    If you want to be able to set values at arbitrary positions, you should populate the list first, e.g. (using generics just because I hate using the raw types):

    List<String> decoded = new ArrayList<String>(10);
    for (int i = 0; i < 10; i++) {
        decoded.add(""); // Or perhaps null
    }
    
    ...
    decoded.set(1, "S"): // This is now fine, replacing element 1
    

    Alternatively, if you already know the size you want, you could use an array to start with – they have a fixed size, and each element is the default value for the element type (so null for strings, for example):

    String[] decoded = new String[10];
    decoded[1] = "S";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code in java : try{ //some code here.. . } catch
I found this article about simple proxy server implemented in JAVA: http://www.java2s.com/Code/Java/Network-Protocol/Asimpleproxyserver.htm The code
Do you guys see any issues with this C# code? It gets email notifications
Hey guys, I have this code for an android application, the funny thing is
hey there guys and girls i have this code that should download a json
Guys, I’ve been writing code for 15+ years, but managed to avoid Web Development
Guys, I've came across this problem I can't resolve myselg, I'm pretty sure I
guys i have arrays in which i have to match this kind of text
Hey guys, I have a problem (again). This time I am trying to use
I have a method like this public static DataSet GetAllDataBaseNames() { //Instance of connection

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.