Here you can find the source of reverseWord(byte[] b)
public static void reverseWord(byte[] b)
//package com.java2s; public class Main { public static void reverseWord(byte[] b) { int len = 0; for (int i = b.length - 1; i >= 0; i--) { if ((b[i] & 0xff) != '\0') { len = i + 1;/*from w w w . j av a2s .c o m*/ break; } } if ((len & 1) == 1) { b[len - 1] = '\0'; len--; } for (int i = 0; i < len / 2; i += 2) { byte tmp = b[i]; b[i] = b[len - 2 - i]; b[len - 2 - i] = tmp; tmp = b[i + 1]; b[i + 1] = b[len - 1 - i]; b[len - 1 - i] = tmp; } } }