1

Just noticed in ByteArrayOutputStream, the toByteArray() is declared as,

public synchronized byte toByteArray()[];

What's the difference between this declaration and the following one?

public synchronized byte[] toByteArray();
ZZ Coder
  • 74,484
  • 29
  • 137
  • 169
  • 3
    Dup of http://stackoverflow.com/questions/129178/difference-between-int-array-and-int-array – skaffman Sep 04 '09 at 16:25
  • 1
    Not a dup, the horrible syntax for array return types is new here. I wouldn't have imagined this could be legal Java. – starblue Sep 04 '09 at 20:30

4 Answers4

5

In this case, none.

If you had declarations:

byte[] a, b;
byte c[], d;

then a, b, and c are byte[], and d is byte.

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
3

There is no difference, though convention amongst programmers strongly prefers the latter.

Brett Kail
  • 33,593
  • 2
  • 85
  • 90
0

Java coding conventions document recommends the second variant (byte[] b). See example.

Roman
  • 64,384
  • 92
  • 238
  • 332
0

BTW, for multidimensional arrays you can also mix both approaches:

public synchronized byte[] to2DByteArray()[];
beetoom
  • 479
  • 3
  • 9