【解決方法】JAVA : 1D 配列の配列リストかどうかを確認する方法


i'm a student in my 1st year, and i need to check if an arrayList of 1D array had a value in index 0, if so i need to keep that value of index 0, and update its value of order [0,1].

What I have tried:

<pre>i created first my 1D array as int [] Order = new int [2];

is a getOrder() methode. asking the user (Server in this case) to add integers ( id of product) and second time to add number of how many pruducts.

and add : Order = {idConso, nbrConso}

than i call the methode from my main(), and passing an arrayList (ord) as a parametre to store the the Orders.

But, when i print the ord ( arrayList of 1D Order array), i shouldn't have the same idConso twice in it.

which means, i need to find a way to check if the idConso (id of the product) is already in ord ( arrayList ) and is so, i need just to check if the arrayList has already idConso and keep it but add the nbrConso (numnbre of orders of that product).

i hope its clear :( thank you.

解決策 1

このようなタスクには単純な配列を使用しないでください。 より良い解決策は マップ (Java プラットフォーム SE 8)[^] これにより、ID をキーとして、カウントを値として使用できます。 また、新しい値を追加する前に、ID が存在するかどうかを確認できます。

コメント

タイトルとURLをコピーしました