例如 String str = "abcdef";转换为str = "123456";效率最高算法;
3 回答

慕容森
TA贡献1853条经验 获得超18个赞
private void getIndex(String str){
byte[] bytes = str.getBytes();
for (int i = 0; i < bytes.length; i++) {
byte b = bytes[i];
System.out.println(b - 96);
}
}

心有法竹
TA贡献1866条经验 获得超5个赞
String a = "abcdefghijklmnopqrst";
byte[] b = a.getBytes();
for (int i = 0; i < b.length; i++) {
b[i] = (byte) (b[i] - 49);
}
System.out.println(new String(b));
- 3 回答
- 0 关注
- 2692 浏览
添加回答
举报
0/150
提交
取消