# ERROR: LoadError: BoundsError: attempt to access 10-element Vector{Int64} at index \[11\]

**URL:** <https://discourse.julialang.org/t/error-loaderror-boundserror-attempt-to-access-10-element-vector-int64-at-index-11/128114>\
**Category:** New to Julia\
**Created:** [April 16, 2025, 7:13am UTC](https://discourse.julialang.org/t/error-loaderror-boundserror-attempt-to-access-10-element-vector-int64-at-index-11/128114 "2025-04-16T07:13:57Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [April 16, 2025, 8:10pm UTC](https://discourse.julialang.org/t/error-loaderror-boundserror-attempt-to-access-10-element-vector-int64-at-index-11/128114/21 "2025-04-16T20:10:46Z")

</div>

> [@hack3rcon](#):
>
> Do you mean that `10` is not a single `Int`?

It is, and eldee didn’t mean that. They meant that you tried to insert an entire 10-element `Vector{Int}` as 1 element of another `Vector{Int}`, which is not possible because `Vector{Int}` can only have elements of `Int`. You would need a `Vector{Vector{Int}}` to do that exact thing, though there are likely better ways to cache each sequence of integers for each line of text, depending on how file.txt is structured.

> [@hack3rcon](#):
>
> Here `10` should be `10`, not `1` and `0`.

There is no separate `1` and `0` there, it really is `10` fitting in one element (we don’t call it cell, but that’s what it is). If you’re wondering why `10` is 2 characters taking twice the space of the smaller integers, it’s just the monospaced printout. A character has nothing to do with the size of the element, and monospacing will never squeeze multiple characters into the space of one.

> [@hack3rcon](#):
>
> When I define an array using `array = fill(0,10)`, what is the maximum number each cell of the array can hold?

mbauman is talking about [_types_](https://en.wikipedia.org/wiki/Data_type), specifically concrete types that can have instances. For example, `"hello"` and `"world"` are instances of the concrete type `String`. For this question, we need to consider 2 purposes of a concrete type:

1. The computer doesn’t directly store the instances `"hello"`, `7`, or `3.14`. There are physical media storing binary data, which we can call 1s and 0s. A concrete type specifies how a segment or multiple segments of binary data represents instances, and users usually don’t need to care about the specifics.

2. A type helps specify what functions/methods can work on its instances. Users do have to know what types can do, and convert between types to do what they want.

As mbauman said, the `String` type can represent integers, and its binary data and thus the integer can get as large as your memory allows. The problem is it is not a type suited for arithmetic, so there aren’t methods implemented for it, e.g. `"1" + "1"` will fail. There are however many numeric types like `Int8`, `Int16`, `Int32`, `Int64`, etc that do support arithmetic, and `parse` can be used to convert `String`s to them, as demonstrated earlier. Numeric types also often have fixed sizes of binary data, so they can support the function `typemax`, which tells you a type’s maximum representable value:

```julia
julia> typemax(Int64)
9223372036854775807

```

If your array’s element type happens to be one of these types, you can extract it with `eltype` and pass it to `typemax`:

```julia
julia> typemax(eltype(fill(0, 10)))
9223372036854775807

```

Note that `Int` (and `UInt`) isn’t the same data type everywhere; it aliases `Int32` on 32-bit systems but `Int64` on 64-bit systems, because of the differences of how they work. As a user, you don’t have to care about all the details, but you should use `Int` for array dimensions/indexing and recognize that the parser will treat integers in text as `Int` (so validate and convert values if you need). You can find out which system via Julia by evaluating `Int` in the REPL and seeing the printout, or `Sys.WORD_SIZE` encodes it directly.

---

<div class="post-metadata">

**Author:** ![hack3rcon](https://avatars.discourse-cdn.com/v4/letter/h/96bed5/32.png) [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Post date:** [April 17, 2025, 12:04pm UTC](https://discourse.julialang.org/t/error-loaderror-boundserror-attempt-to-access-10-element-vector-int64-at-index-11/128114/22 "2025-04-17T12:04:52Z")

</div>

Hello,  
Let’s assume the contents of the file `file.txt` are as follows:

```julia
9 10

```

Is it possible for you to explain the following code step by step?

```julia
    array = fill(0,10)
    counter = 1
    for line in eachline("file.txt")
        if line != ' '
            array[counter] = parse.(Int, split(line))
            counter +=1
        end
    end

```

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [April 17, 2025, 12:25pm UTC](https://discourse.julialang.org/t/error-loaderror-boundserror-attempt-to-access-10-element-vector-int64-at-index-11/128114/23 "2025-04-17T12:25:06Z")

</div>

I’m not sure what to explain, can I ask what the goal is? That code is known not to work and the error has been explained, so I don’t know what else about it you want to know, and if you want to see step-by-step values, you can use the REPL to evaluate the lines. Well, you would have to break the for loop into separate `iterate` calls if you’re not using a debugger, though you’d hit the error on the first iteration anyway.

---

<div class="post-metadata">

**Author:** ![hack3rcon](https://avatars.discourse-cdn.com/v4/letter/h/96bed5/32.png) [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Post date:** [April 19, 2025, 6:17am UTC](https://discourse.julialang.org/t/error-loaderror-boundserror-attempt-to-access-10-element-vector-int64-at-index-11/128114/24 "2025-04-19T06:17:09Z")

</div>

Hi,  
Thanks again.  
How can I fix the problem with the following code without using additional, advanced functions?

```julia
function arrayandfile()
    array = fill(0,10)
    counter = 1
    for line in eachline("file.txt")
        if line != ' '
            array[counter] = parse.(Int, split(line))
            counter +=1
        end
    end
    return(array)
end
println(arrayandfile())

```

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [April 19, 2025, 7:54am UTC](https://discourse.julialang.org/t/error-loaderror-boundserror-attempt-to-access-10-element-vector-int64-at-index-11/128114/25 "2025-04-19T07:54:58Z")

</div>

> [@eldee](#):
>
> You could use
> 
> ```julia
> function arrayandfile()
> array = fill(0, 10) # where 10 is the total number of values in the file
> counter = 0 # number of values actually put in array so far
> for line in eachline("file.txt")
> line_values = parse.(Int, split(line))
> array[counter + 1 : counter + length(line_values)] .= line_values
> counter += length(line_values)
> end
>     
> return array
> end
> 
> ```

I’m not sure why this does not fulfil your criteria…

---

<div class="post-metadata">

**Author:** ![eteppo](https://avatars.discourse-cdn.com/v4/letter/e/90db22/32.png) [@eteppo](https://discourse.julialang.org/u/eteppo)\
**Post date:** [April 19, 2025, 11:16am UTC](https://discourse.julialang.org/t/error-loaderror-boundserror-attempt-to-access-10-element-vector-int64-at-index-11/128114/26 "2025-04-19T11:16:04Z")

</div>

Looping over things one by one is a fine place to start if you find it easy to understand. The only issue with your original code was that it was looping over individual characters like `'1'`, `' '`, `'2'`, `'\n'` (new line), and so on, not strings like `"1"`, `"10"`. See if this function makes sense to you. And happy learning, it’ll all make more sense soon enough.

```julia
function arrayandfile()
    # Create a collection of ten zeros as a placeholder.
    array = fill(0,10)
    counter = 1
    # Get each line in the file as a string like "1 2 10".
    for line in eachline("file.txt")
        # Split the line into a collection of pieces like ["1", "2", "10"] without spaces.
        pieces = split(line)
        # Get each piece like "1" or "10" from the collection.
        for piece in pieces
            # Transform the piece into an actual number (type Int, integer).
            integer = parse(Int, piece)
            # And insert it into the array at the position given by the counter.
            array[counter] = integer
            # Increment the counter.
            counter += 1
        end
    end
    return array
end

arrayandfile()

```

---

<div class="post-metadata">

**Author:** ![hack3rcon](https://avatars.discourse-cdn.com/v4/letter/h/96bed5/32.png) [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Post date:** [April 27, 2025, 6:15am UTC](https://discourse.julialang.org/t/error-loaderror-boundserror-attempt-to-access-10-element-vector-int64-at-index-11/128114/27 "2025-04-27T06:15:49Z")

</div>

Hi,  
Thank you so much.

[Previous page](https://discourse.julialang.org/t/error-loaderror-boundserror-attempt-to-access-10-element-vector-int64-at-index-11/128114.md?page=1)
