当前位置: 代码迷 >> Java相关 >> 数组问题
  详细解决方案

数组问题

热度:285   发布时间:2007-04-24 20:43:41.0
数组问题

import java.util.*;
class b{
String Name,Street,City,country,pincode;
b(String Name,String Street,String City,String country,String pincode)
{
this.City=City;
this.Name=Name;
this.country=country;
this.pincode=pincode;
this.Street=Street;
}
}
public class zuoye {
public static void main(String[]args)
{ ArrayList aa=new ArrayList();
aa.add(new b("David Clarke","10 downing Street","LondonState:London","United Kingdom","110022"));
aa.add(new b("John Lenon","12 Park Avenue","CaliforniaState:California","USA","210033"));
aa.add(new b("Stefii Graff","14 Maple Lane","MahomaState: Sydney","Australia","412033"));
System.out.println("*************************");
System.out.println("客户电子邮件地址");
System.out.println("*************************");
System.out.println("[");
for(int i=0;i<aa.size();i++)
{
System.out.println("Name:"+aa.get(i).Name);
System.out.println("Street:"+aa.get(i).Street);
System.out.println("City:"+aa.get(i).City);
System.out.println("country:"+aa.get(i).country);
System.out.println("pincode:"+aa.get(i).pincode);
System.out.println();
}
System.out.println("]");
}


}





System.out.println("Name:"+aa.get(i).Name);
System.out.println("Street:"+aa.get(i).Street);
System.out.println("City:"+aa.get(i).City);
System.out.println("country:"+aa.get(i).country);
System.out.println("pincode:"+aa.get(i).pincode);
System.out.println();
这应该怎么改呢??

搜索更多相关的解决方案: String  Street  City  country  pincode  

----------------解决方案--------------------------------------------------------
用泛型
----------------解决方案--------------------------------------------------------
b p=(b) aa.get(i);
System.out.println("Name:"+p.Name);
System.out.println("Street:"+p.Street);
System.out.println("City:"+p.City);
System.out.println("country:"+p.country);
System.out.println("pincode:"+p.pincode);
System.out.println();
这样吗?/
----------------解决方案--------------------------------------------------------
ArrayList<b> aa=new ArrayList();
这样你下面不用b p=(b) aa.get(i);
强制类型转化了。

----------------解决方案--------------------------------------------------------
  相关解决方案