---
title: "Array i array"
type: "forum-thread"
url: "https://www.webforum.nu/amne/java/128914-array-i-array"
topic: "Java"
topic_url: "https://www.webforum.nu/amne/java"
author: "xcalibrate"
published: "2005-05-26T18:47:36.000Z"
updated: "2005-05-27T11:45:05.000Z"
replies: 1
views: 378
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/java/128914-array-i-array"
---

# Array i array

## #1 — xcalibrate, 2005-05-26T18:47Z

Hej, jag vill förkorta denna lilla kodbit i Java så att jag slipper ha flera variabler med arrays. Utan en array i en array (\[\]\[\]).

Såhär ser det ut nu:

```
int[] Account1Cash = new int[MaxUserValue];
int[] Account2Cash = new int[MaxUserValue];
int[] Account3Cash = new int[MaxUserValue];
int[] Account4Cash = new int[MaxUserValue];
int[] Account5Cash = new int[MaxUserValue];
```

MaxUserValue = 100

Men jag tänte att man instället kanske skulle kunna ha
int\[\]\[\] AccountCash = new int\[5\]\[MaxuserValue\]; eller något?
Någon somvet vad som motsvarar mina krav?

Nu måste jag sitta och kolla sen när jag ska avnända variablerna såhär:

```
if (Account1Cash[UserNumberAccount] == 1) {
System.out.println("\nCreate Account >> Account does already exists\n");
return;
}
```

Och sen Account1Cash osv osv... kanske vore lättare om man typ kunde skriva AccountCash\[UserNumberAccount\]\[?\] eller nått. Jag vet inte.

Permalänk: https://www.webforum.nu/p/128914

## #2 — Peter S, 2005-05-27T11:45Z

Tjena!

```
int[][] AccountCash = new int[5][];

for (int i = 0; i < AccountCash.length; ++i){
    AccountCash[i] = new int[MaxUserValue];
}
```

Permalänk: https://www.webforum.nu/p/1620684

---

Tråden på webben: https://www.webforum.nu/amne/java/128914-array-i-array
