Java String类的构造方法求大神教
importjavax.swing.*;publicclassStringTest{Stringstring1,string2,string3,string4;byte[...
import javax.swing.*;
public class StringTest {
String string1,string2,string3,string4;
byte[]byte1={72,101,108,111,32,110,101,119,32,87,111,114,108,100};
char[]char2={'H','e','l','l','o',' ','n','e','w',' ','w','o','r','d'};
public StringTest(){
string1=new String();
string2=new String(byte1,6,9);
string3=new String(char2,0,5);
string4=JOptionPane.showInputDialog("Input a String:");
System.out.println();
System.out.println("String1:"+string1);
System.out.println("String2:"+string2);
System.out.println("String3:"+string3);
System.out.println("String4:"+string4);
}
public static void main(String args[]){
StringTest st=new StringTest();
System.exit(-1);
}
}
报错找不到 展开
public class StringTest {
String string1,string2,string3,string4;
byte[]byte1={72,101,108,111,32,110,101,119,32,87,111,114,108,100};
char[]char2={'H','e','l','l','o',' ','n','e','w',' ','w','o','r','d'};
public StringTest(){
string1=new String();
string2=new String(byte1,6,9);
string3=new String(char2,0,5);
string4=JOptionPane.showInputDialog("Input a String:");
System.out.println();
System.out.println("String1:"+string1);
System.out.println("String2:"+string2);
System.out.println("String3:"+string3);
System.out.println("String4:"+string4);
}
public static void main(String args[]){
StringTest st=new StringTest();
System.exit(-1);
}
}
报错找不到 展开
2个回答
展开全部
string2=new String(byte1,6,9);这个错了,最后一个参数是指定要截取的数组的长度,而不是指最后一个byte的索引,若要取byte1的第6-9数组成员,用new String(byte1,6,3);
追问
谢谢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询