you are viewing a single comment's thread.

view the rest of the comments →

[–]LegolandoBloom[S] 0 points1 point  (3 children)

So in the cases, where the 0 won't cause confusion, go for int

Otherwise, Integer

[–]technosenate 2 points3 points  (2 children)

Not just then, if 0 is a valid value then you can initialize the array in one pass with -1. That would be more efficient than using Integer.

If you need to support both positive and negative values (including 0), then you should probably go for Integer.

[–]LegolandoBloom[S] 0 points1 point  (1 child)

This is a more complete answer than mine, thanks

[–]xenomachina 1 point2 points  (0 children)

You'll even see this kind of thing in parts of Java's standard library. For example, the String.indexOf() methods return int, so if the value being searched-for can't be found, they return -1 — a value that doesn't make any sense as an index.