public byte[] getBytes() Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array. The behavior of this method when this string cannot be encoded in the default charset is unspecified. The CharsetEncoder class should be used when more control over the encoding process is required. Returns: The resultant byte array
String s = new String("Hello the world!"); byte[] bytes = s.getBytes();
实际中查看JAVA API很重要。 找到该类,再查看其对应方法,一般看名字就大概了解该方法是干啥的
String s = new String("This is the right result!"); byte[] bytes = s.getBytes(); 建议看<<Core Java>>一书,就不会有这样的问题了!
public class example1 { public static void main(String []arg){ String s = new String("This is java application!"); byte[] sbyte = s.getBytes(); for (int i=0; i<sbyte.length; i++) System.out.println(sbyte[i]); System.out.println("i = "+sbyte.length); }}
public class Test{ public static void main(String[] args){ String s=new String("abcdefgh"); byte[] b=s.getBytes(); for (int i=0; i<b.length; i++) System.out.println(" "+(char)b[i]); } }
这个也太。
Encodes this String into a sequence of bytes using the platform's default charset, storing the result into a new byte array.
The behavior of this method when this string cannot be encoded in the default charset is unspecified. The CharsetEncoder class should be used when more control over the encoding process is required.
Returns:
The resultant byte array
byte[] bytes = s.getBytes();
找到该类,再查看其对应方法,一般看名字就大概了解该方法是干啥的
byte[] bytes = s.getBytes();
建议看<<Core Java>>一书,就不会有这样的问题了!
public static void main(String []arg){
String s = new String("This is java application!");
byte[] sbyte = s.getBytes();
for (int i=0; i<sbyte.length; i++)
System.out.println(sbyte[i]);
System.out.println("i = "+sbyte.length);
}}
public static void main(String[] args){
String s=new String("abcdefgh");
byte[] b=s.getBytes();
for (int i=0; i<b.length; i++)
System.out.println(" "+(char)b[i]);
}
}
这个方法怎么没见你们定义出来呀。
我也是初学JAVA者,请各位帮忙就帮到底,把这个方法说清楚些
怎么办呢?我离开书什么都做不了.
不要说你们两个的jdk没有java.util.String这个类
开始的时候是这样的,时间长了能记住方法在什么包中了,熟能生巧吗!~
String.getBytes()
我要出发了,随便看看!
这种分不接对不起你,去查一下API手册就知道了,跑着问,我服了你了,你要是这个水平的话,连一个编程爱好者都算不上
String s = new String("i am a new guy!");
byte[] bytes = s.getBytes();
大家共同努力就是了!!!
没有谁天生就是将军 的!!!谢谢你的提问!