日期:2014-05-20 浏览次数:20812 次
import java.util.ArrayList; public class StrDemo { public static void main(String[] args) { ArrayList ary=new ArrayList(); Str st=new Str("Dacid Clarke","10 Doening Street","LondnState : London", "United Kingdom","110022"); Str st1=new Str("John Lenon","12 Park Avenue","CliforniaState : CaliFornia", "USA","210033"); Str st2=new Str("Stefii Graff","14 Mape Lane","LondonState : Sydney","Australia","412033"); ary.add(st.getArry()); for(int i=0;i<=5;i++){ System.out.println(ary.get(i)); } } }
import java.util.ArrayList; public class Str { private ArrayList arry=new ArrayList(); private String name; private String Street; private String City; private String Country; private String Picde; public Str(String str,String st2,String st3,String st4,String st5){ name=str; Street=st2; City=st3; Country=st4; Picde=st5; } public void setArry(){ arry.clear(); arry.add(name); arry.add(Street); arry.add(City); arry.add(Country); arry.add(Picde); } public ArrayList getArry(){ return arry; } public void print(){ for(int i=0;i<5;i++){ System.out.println(arry.get(i)); } } }
import java.util.ArrayList; class Str { private String name; private String Street; private String City; private String Country; private String Picde; public Str(String str,String st2,String st3,String st4,String st5){ name=str; Street=st2; City=st3; Country=st4; Picde=st5; } public String toString(){ StringBuffer sb = new StringBuffer(); sb.append("name :").append(name).append("\n"); sb.append("Street :").append(Street).append("\n"); sb.append("City :").append(City).append("\n"); sb.append("Country :").append(Country).append("\n"); sb.append("Picde :").append(Picde).append("\n"); return sb.toString(); } } public class StrDemo { public static void main(String[] args) { ArrayList<Str> ary=new ArrayList<Str>(); Str st=new Str("Dacid Clarke","10 Doening Street","LondnState : London", "United Kingdom","110022"); Str st1=new Str("John Lenon","12 Park Avenue","CliforniaState : CaliFornia", "USA","210033"); Str st2=new Str("Stefii Graff","14 Mape Lane","LondonState : Sydney","Australia","412033"); ary.add(st); ary.add(st1); ary.add(st2); for(int i=0;i<ary.size();i++){ System.out.println(ary.get(i)); } } }
------解决方案--------------------
UserInfo.java
package com.hundsun.zhoujl; /** * @author zhoujl * 2011/12/27 14:37:27 */ public class UserInfo { private String name; private String street; private String city; private String country; private String picde; /** * @param name * @param street * @param city * @param country * @param picde */ public UserInfo(String name, String street, String city, String country, String picde) { super(); this.name = name; this.street = street; this.city = city; this.country = country; this.picde = picde; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getStreet() { return street; } public void setStreet(String street) { this.street = street; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country; } public String getPicde() { return picde; } public void setPicde(String picde) { this.picde = picde; } @Override public String toString() { return "Name:"+name+"\n"+"Street:" + street+"\n"+"City:"+city+"\n" +"Country:"+country+"\n"+"Picde:"+picde; } }
------解决方案--------------------