String类里的方法:
//indexOf()返回某个指定的字符串值(必需)在字符串中指定的位数(非必需)后首次出现的位置
String str="java字符串";
int i=str.indexOf("符",4); //i=5
//trim()截取中间的非空白字符返回(截掉了字符串两端Unicode编码小于等于32(\u0020)的所有字符)
String s="90 汉 \u0019";
String trim = s.trim();
System.out.println(s+","+s.length()); //90 汉 ,6
System.out.println(trim+","+trim.length()); //90 汉,4
位运算:
符号 | 描述 | 运算规则 |
---|---|---|
& | 与 | 两个位都为1时,结果才为1 |
| | 或 | 两个位都为0时,结果才为0 |
^ | 异或 | 两个位相同为0,相异为1 |
~ | 取反 | 0变1,1变0 |
<< | 左移 | 各二进位全部左移若干位,高位丢弃,低位补0 |
>> | 右移 | 各二进位全部右移若干位,对无符号数,高位补0,有符号数,各编译器处理方法不一样,有的补符号位(算术右移),有的补0(逻辑右移) |
输出方法:
//输出ByteBuf:
while (buf.isReadable()) {
System.out.print(buf.readByte());
}