public class CharUtil {
来源:互联网 发布:linux中的find命令 编辑:程序博客网 时间:2024/06/03 14:12
import java.nio.ByteBuffer;
public class CharUtil {
public static final int LARGE_CHARS_THRESHOLD = 1024;
public static char[] merge(char[] chars0, char[] chars1) {
if (chars0.length == 0) {
return chars1;
} else if (chars1.length == 0) {
return chars0;
}
int capacity = chars0.length + chars1.length;
char[] chars = new char[capacity];
int pos = 0;
int length = chars0.length;
System.arraycopy(chars0, 0, chars, pos, length);
pos += length;
length = chars1.length;
System.arraycopy(chars1, 0, chars, pos, length);
return chars;
}
public static byte[] toBytes(char[] chars) {
return CharToByte.toBytes(chars);
}
public static byte[] toAsciiBytes(char[] chars) {
return CharToByte.toAsciiBytes(chars);
}
public static String toUnicodeString(char c) {
return Integer.toHexString((int) c);
}
public static String toUnicodeString(String s) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
if (i > 0) {
builder.append(' ');
}
builder.append(toUnicodeString(s.charAt(i)));
}
return builder.toString();
}
public static void main(String[] args) throws Exception {
String s = "fudan1988";
char[] chars = s.toCharArray();
byte[] bytes = toBytes(chars);
ByteBuffer byteBuffer = ByteBuffer.allocate(bytes.length);
byteBuffer.put(bytes);
byteBuffer.flip();
char[] chars1 = new char[chars.length];
for (int i = 0; i < chars1.length; i++) {
chars1[i] = byteBuffer.getChar();
}
for (int i = 0; i < chars.length; i++) {
assert chars[i] == chars1[i];
}
}
}
0 0
- public class CharUtil {
- public class与public partial class
- public class与public partial class 区别
- public class与public partial class
- public class Object
- C# public class Person
- class CrobotApp : public CWinApp
- class CSplitterWnd :public CSplitterWnd
- class IconEditor : public QWidget
- public class MyEclipseRegister{
- C++ public class
- public class staticInter
- public class Unname2
- public class CharToByte {
- public class ByteUtil {
- public class Engineer
- public class ExcelImageTes
- public class LuoxuanArray
- 卡方选择(chi-square)能用到logistic regression当中么?(一)
- 《学习OpenCV》练习3-2
- ScrollView与ListView合用(正确计算Listview的高度)的问题解决
- public class CharToByte {
- public class ByteUtil {
- public class CharUtil {
- PROPAGATION_REQUIRES_NEW 和 PROPAGATION_NESTED区别
- 【转】ARM汇编 MOV PC,LR
- Notice: Undefined variable: data in /var/www/html/bbeden/modoer/ecshop/includes/lib_base.php on line
- 《学习OpenCV》打印矩阵
- Fighting (完全背包问题)
- 理解JavaScript的caller,callee,call,apply
- 把过程与函数说透
- 小P寻宝记(01背包)