| 8 | |
| 9 | public class Endians { |
| 10 | public static void main(String[] args) { |
| 11 | ByteBuffer bb = ByteBuffer.wrap(new byte[12]); |
| 12 | bb.asCharBuffer().put("abcdef"); |
| 13 | System.out.println(Arrays.toString(bb.array())); |
| 14 | bb.rewind(); |
| 15 | bb.order(ByteOrder.BIG_ENDIAN); |
| 16 | bb.asCharBuffer().put("abcdef"); |
| 17 | System.out.println(Arrays.toString(bb.array())); |
| 18 | bb.rewind(); |
| 19 | bb.order(ByteOrder.LITTLE_ENDIAN); |
| 20 | bb.asCharBuffer().put("abcdef"); |
| 21 | System.out.println(Arrays.toString(bb.array())); |
| 22 | } |
| 23 | } |
| 24 | /* Output: |
| 25 | [0, 97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102] |