Z
zero
Hi everyone,
I'm trying to reverse an array of bytes using Collections.reverse:
<code>
byte[] theBytes = { 1, 2, 3 };
System.out.println( Arrays.toString( theBytes ) );
Collections.reverse( Arrays.asList( theBytes ) );
System.out.println( Arrays.toString( theBytes ) );
</code>
However, his prints
[1, 2, 3]
[1, 2, 3]
ie, the array is not reversed at all. When however I do the exact same
thing with a String array, it works:
<code>
String[] theStrings = { "Hello", "World" };
System.out.println( Arrays.toString( theStrings ) );
Collections.reverse( Arrays.asList( theStrings ) );
System.out.println( Arrays.toString( theStrings ) );
</code>
This gives the (expected) output:
[Hello, World]
[World, Hello]
What am I missing here?
TIA,
zero
I'm trying to reverse an array of bytes using Collections.reverse:
<code>
byte[] theBytes = { 1, 2, 3 };
System.out.println( Arrays.toString( theBytes ) );
Collections.reverse( Arrays.asList( theBytes ) );
System.out.println( Arrays.toString( theBytes ) );
</code>
However, his prints
[1, 2, 3]
[1, 2, 3]
ie, the array is not reversed at all. When however I do the exact same
thing with a String array, it works:
<code>
String[] theStrings = { "Hello", "World" };
System.out.println( Arrays.toString( theStrings ) );
Collections.reverse( Arrays.asList( theStrings ) );
System.out.println( Arrays.toString( theStrings ) );
</code>
This gives the (expected) output:
[Hello, World]
[World, Hello]
What am I missing here?
TIA,
zero