Click here to Skip to main content
15,886,840 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.
Posted
Updated 11-Dec-22 22:31pm
Comments
OriginalGriff 12-Dec-22 3:58am    
And?
What have you tried?
Where are you stuck?
What help do you need?

Use the "Improve question" widget to edit your question and provide better information.

1 solution

You should not use a simple array for a task like this. A better solution would be a Map (Java Platform SE 8 )[^] which allows you to use the id as the key and the count as the value. And you can check if the id exists before adding new values.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900