# Assigning Values to Arrays

## Assigning Values

After being created/declared, access and element or “slot” of the array variable by its index.

Picture an array like a numbered list starting at zero...

| shoppingList |                 |
| ------------ | --------------- |
| 0            | "milk"          |
| 1            | "bread"         |
| 2            | "eggs"          |
| 3            | "bottled water" |
| 4            | "soda"          |

| ages |    |
| ---- | -- |
| 0    | 12 |
| 1    | 31 |
| 2    | 7  |
| 3    | 80 |
| 4    | 45 |
| 5    | 50 |
| 6    | 51 |
| 7    | 50 |

**Example Code:**

*Processing:*

```java
shoppingList[0] = "milk";
shoppingList[1] = "bread";
shoppingList[2] = "eggs";
shoppingList[3] = "bottled water";
shoppingList[4] = "soda";
```

```java
ages[0] = 12;
ages[1] = 31;
ages[2] = 7;
ages[3] = 80;
ages[4] = 45;
ages[5] = 50;
ages[6] = 51;
ages[7] = 50;
```

```java
for (int i = 0; i < randNums.length(); i++) {
	randNums[i] = random(0, 5);
}
```

Equivalent to:

```java
randNums[0] = random(0, 5);
randNums[1] = random(0, 5);
randNums[2] = random(0, 5);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hopemoore.gitbook.io/coding-for-creatives-spring-2021/glossary-and-terms/arrays/assigning-values-to-arrays.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
