java中,tostring如何重写,显示数据,请补充
如下程序缺少toString函数没有填写,请补充,使现在运行为数据,不是地址的乱码importjava.util.*;publicclasspokeimplementsC...
如下程序缺少toString函数没有填写,请补充,使现在运行为数据,不是地址的乱码
import java.util.*;
public class poke implements Comparable<poke>{
public static void main(String[] args) {
// TODO 自动生成方法存根
List<poke> arraylist = new ArrayList<poke>();
int i,j,k;
String[] huase ={"Hongtao","Fangkuai","Heitao","Meihua"};
String[] num = {"1","2","3","4","5","6","7","8","9","10","J","Q","K"};
for(i=1; i<3; i++){
for(j=0; j<4; j++){
for(k=0; k<13; k++)
arraylist.add(new poke(num[k],huase[j],i));
}
}
System.out.println(arraylist);
}
public String Number;
public String Huase;
public int PaiID;
public poke(String number,String huase,int paiID){
this.Number = number;
this.Huase = huase;
this.PaiID = paiID;
}
public String getHuase() {
return Huase;
}
public void setHuase(String huase) {
Huase = huase;
}
public String getNumber() {
return Number;
}
public void setNumber(String number) {
Number = number;
}
public int getPaiID() {
return PaiID;
}
public void setPaiID(int paiID) {
PaiID = paiID;
}
public int compareTo(poke p) {
// TODO 自动生成方法存根
return 0;
}
public String toSting(){
return Huase+Number;
}
} 展开
import java.util.*;
public class poke implements Comparable<poke>{
public static void main(String[] args) {
// TODO 自动生成方法存根
List<poke> arraylist = new ArrayList<poke>();
int i,j,k;
String[] huase ={"Hongtao","Fangkuai","Heitao","Meihua"};
String[] num = {"1","2","3","4","5","6","7","8","9","10","J","Q","K"};
for(i=1; i<3; i++){
for(j=0; j<4; j++){
for(k=0; k<13; k++)
arraylist.add(new poke(num[k],huase[j],i));
}
}
System.out.println(arraylist);
}
public String Number;
public String Huase;
public int PaiID;
public poke(String number,String huase,int paiID){
this.Number = number;
this.Huase = huase;
this.PaiID = paiID;
}
public String getHuase() {
return Huase;
}
public void setHuase(String huase) {
Huase = huase;
}
public String getNumber() {
return Number;
}
public void setNumber(String number) {
Number = number;
}
public int getPaiID() {
return PaiID;
}
public void setPaiID(int paiID) {
PaiID = paiID;
}
public int compareTo(poke p) {
// TODO 自动生成方法存根
return 0;
}
public String toSting(){
return Huase+Number;
}
} 展开
4个回答
2015-12-03 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
1. 在eclipse中按住快捷键alt+shif+s
2. 选择Generate toString();自动生成
public String toString() {
return "poke [Number=" + Number + ", Huase=" + Huase + ", PaiID="
+ PaiID + "]";
}
展开全部
List<poke> arraylist = new ArrayList<poke>();
System.out.println(arraylist);
你要重写ArrayList类的方法不过直接改好像不行,你写个子类继承ArrayList
再重写下toString方法
System.out.println(arraylist);
你要重写ArrayList类的方法不过直接改好像不行,你写个子类继承ArrayList
再重写下toString方法
追问
怎么样修改,可以的话,直接修改,把代码发过来吧。。。谢谢
追答
1. 写个类继承ArrayList , 只重写toString方法
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public String toString(){
return a+b+c://所需要的串
}
return a+b+c://所需要的串
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询