List練習
import java.util.ArrayList; import java.util.HashSet; import java.util.List;
public class String_char { public static void main(String args[]) { List<String>a=new ArrayList<String>(); a.add("First"); a.add("Second"); String str1="hsuaaggcdg"; System.out.println(str1.toString());; a.add("Thrid"); HashSet<String>b=new HashSet<String>(); b.add("a"); System.out.println(b); System.out.println(a); List<Items>c=new ArrayList<Items>(); c.add(new CD("張傑", "娜扎")); c.add(new CD("張傑","劉傑")); System.out.println(c.toString()); } }
public class CD extends Items { private String name; private String artist; public CD(String name, String artist) { super(); this.name = name; this.artist = artist; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getArtist() { return artist; } public void setArtist(String artist) { this.artist = artist; } @Override public String toString() { return "CD [name=" + name + ", artist=" + artist + "]"; } }
public class Items { private String name; private String artist; public Items(String name, String artist) { super(); this.name = name; this.artist = artist; } public Items() { } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getArtist() { return artist; } public void setArtist(String artist) { this.artist = artist; } }