#need help with arraylist

39 messages · Page 1 of 1 (latest)

shy estuary
#

im trying to make it print raw oyster special x4 instead of printing 4 separate time

late birchBOT
#

This post has been reserved for your question.

Hey @shy estuary! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

nova arch
#

You could create a variable to count how many raw oyster specials you have then loop through your list and increment it for each raw oyster special

median mural
#

you'd have to count them up, i suppose
probably with a map, so like A, B, A gets reduced to A x2, B correctly
or you could store them in a map to begin with, to track their counts directly, rather than using a list

nova arch
#

But it might require some minor refactoring

shy estuary
nova arch
#

Its ok

shy estuary
late birchBOT
median mural
#

there's an section on the collections api there, with an article on maps

nova arch
#

<string, integer>

shy estuary
#

does it have to be capitalized?

#

ArrayList<String> orderL = new ArrayList<String, int>();

median mural
#

it needs to be Integer, primitives cannot be used as generics

shy estuary
#

ok

median mural
#

but yes, capitalized, because they're reference types

nova arch
#

Integer is the wrapper class for int

shy estuary
#

ArrayList<String> orderL = new ArrayList<String, Integer>();

#

or would i need to add integer on the front one as well

median mural
#

lists and maps are completely different structures

shy estuary
#

ok so keep it as it is

median mural
#

no

shy estuary
#

ArrayList<String, Integer> orderL = new ArrayList<String, Integer>();

median mural
#

List<E> list = new ArrayList<>(); or whatever for lists, but that obviously doesn't work to create maps

#

lists are not maps

#

read the guide please

#

Map<K, V> map = new HashMap<>();

#

with the proper K and V

shy estuary
#

but i used ArrayList<String> orderL = new ArrayList<String>(); and worked

median mural
#

works to create a list, yes

#

doesn't work to create a map

nova arch
#

Map != list

shy estuary
#

oh

#

i got confused for a sec

nova arch
#

Map hierarchy