java打印List问题 请教高手帮忙

[复制链接]
查看11 | 回复3 | 2011-2-20 21:51:30 | 显示全部楼层 |阅读模式
重写写class Elem的toString方法就可以了,修改后代码如下:import java.util.*;public class ListTest {
class Elem
{
private String name;
private int age;
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name = name;
}
...
回复

使用道具 举报

千问 | 2011-2-20 21:51:30 | 显示全部楼层
重写toString()方法!!!public String toString(){
retrun name+","+age;}...
回复

使用道具 举报

千问 | 2011-2-20 21:51:30 | 显示全部楼层
class Elem
{//添加以下这段
public String toString(){
returnthis.name + "," + this.age;
}}...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行