如何使用Java从字符串中获取单个字符?

-1 java

例如,"this is yahoo answers"从这里我想要获取每个单个字符并将其转换为ASCII值.我该怎么做?

Bal*_*usC 5

你的问题有点模糊,但可能你想要这个?

for (char c : "this is yahoo answers".toCharArray()) {
    System.out.println((int) c);
}
Run Code Online (Sandbox Code Playgroud)

这产生以下结果:

116
104
105
115
32
105
115
32
121
97
104
111
111
32
97
110
115
119
101
114
115

转换charint将显示其代码点.