The concept of containers
Container API
Collection Interface
ImportJava.util.*; Public classBasiccontainer { Public Static voidMain (string[] args) {Collection C=NewHashSet (); C.add ("Hello"); C.add (NewName ("F1", "L1")); C.add (NewInteger (100)); C.remove ("Hello"); C.remove (NewInteger (100)); System.out.println (C.remove (NewName ("F1", "L1"))); System.out.println (c); }}classNameImplementsComparable {PrivateString Firstname,lastname; PublicName (String firstName, String lastName) { This. firstName = FirstName; This. LastName =LastName; } PublicString Getfirstname () {returnFirstName; } PublicString Getlastname () {returnLastName; } PublicString toString () {returnFirstName + "" +LastName; } Public Booleanequals (Object obj) {if(objinstanceofName) {Name Name=(Name) obj; return(Firstname.equals (name.firstname))&&(Lastname.equals (name.lastname)); } return Super. Equals (obj); } Public inthashcode () {returnFirstname.hashcode (); } Public intcompareTo (Object o) {Name n=(Name) o; intLASTCMP =Lastname.compareto (n.lastname); return(lastcmp!=0?LastCmp:firstName.compareTo (n.firstname)); } }
Basiccontainer.java
Iterator Interface
Examples of Iterator methods
Supplemental: JDK1.5 enhanced for Loop
ImportJava.util.*; Public classEnhancedfor { Public Static voidMain (string[] args) {int[] arr = {1, 2, 3, 4, 5}; for(intI:arr) {System.out.println (i); } Collection C=NewArrayList (); C.add (NewString ("AAA")); C.add (NewString ("BBB")); C.add (NewString ("CCC")); for(Object o:c) {System.out.println (o); } }}
Enhancedfor.javaset Interface
Example of Set method
List Interface
List Method Examples
List Common algorithms
List Common algorithm examples
comparable Interface
How to choose a data interface *
Container of J2SE _collection_iterator_set_list_comparable