Add several values to IntList

Hi,

I’m starting to use IntList in a project, not absolutely comfortable with everything yet…
I’m seeing in the documentation that I can add several int at once with myList.append(values) or myList.append(list) but each time i’m trying to add something more than a single integer, i’m getting this error:

the function "append()" expects parameters like: "append(int)"

Does any body have some experience with this?

thanks!

Hi! Like this:

IntList inventory = new IntList();
inventory.append(1);
inventory.append(new int[] {2, 3, 4});

@hamoid thanks a lot ! Among all the things I’ve tried I don’t think I would ever find this one by myself!

Thanks again

Indeed there’s no explanation whatsoever about what .append(values) and .append(list) arguments actually mean! :-1:

I had to look at the source code in order to know all of its overloaded signatures: :roll_eyes:

final IntList vals = new IntList();

vals.append(0);
println(vals);

vals.append(new int[] { 84, 15, 102 });
println(vals);

vals.append(new IntList( -5, 11 ));
println(vals);

exit();

Indeed a good way to proceed!
I’ll keep that in mind a try to dig myself in the source code next time i’m facing that problem! :+1:

Also, it’s a pity we need to create a whole array in order to pass multiple values to append().
vals.append(new int[] { 84, 15, 102 });

Funny, IntList’s constructor is overloaded to do just that:
vals.append(new IntList( -5, 11 ));

By just changing public void append(int[] values) { to public void append(int... values) {, we could invoke it like this:
vals.append( 84, 15, 102 );

2 Likes

Finally i get the difference between [] and … . I looked some Time ago for Hours, only to get told that they are both the Same… had to work with hashmaps in an old project to get that functionality…

The autocomplete in IntelliJ Idea told me…
Screenshot%20from%202018-10-23%2017-04-37 Screenshot%20from%202018-10-23%2017-04-13

AFAIK, variadic parameters exist in Java since version 5. :coffee:

IMO, it’s a huge oversight that Processing’s source code don’t use such ancient feature in as many places as possible! :eye:

Java is already version 11 now! :flushed:

1 Like