Container of J2SE _collection_iterator_set_list_comparable

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.