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
  • 72,880
  • 29
  • 134
  • 165
  • 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.

Chris Jester-Young
  • 213,251
  • 44
  • 377
  • 423
3

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

Brett Kail
  • 33,148
  • 2
  • 86
  • 88
0

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

Roman
  • 61,962
  • 88
  • 232
  • 324
0

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

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