Collection Framework (Basic functional testing of the collection collection)

Source: Internet
Author: User

Collection Interface Overview
The root interface in the Collection hierarchy. Collection represents a set of objects, also known as Collection elements. Some collection allow duplicate elements, while others do not. Some of the collection are orderly, while others are unordered.

Boolean Add (E E)
Boolean remove (Object o)
void Clear ()
Boolean contains (Object o)
Boolean IsEmpty ()
int size ()

Write a test class below to test the method above

Package Cn.itcast_01;import Java.util.arraylist;import java.util.Collection;
Public class collectiondemo { public static void main (String[] args)  {   //  test methods without all   //  create a collection object   // collection c  = new collection ();  //error because interface is not instantiated   Collection c = new  ArrayList ();   // boolean add (object obj): Add an element   // system.out.println ("Add:" +c.add ("Hello"));   c.add ("Hello");   c.add ("World");   c.add ("Java");   // void clear (): Remove all elements   // c.clear ();   // boolean remove ( Object o): Removes an element   // system.out.println ("Remove:"  + c.remove ("Hello"));   // system.out.println ("Remove:"  + c.remove ("Java ee"));(delete elements not in the original collection, return False, the elements of the collection are not changed, No effect on the original set)   // boolean contains (Object o): Determines whether the collection contains the specified element   //  System.out.println ("contains:" +c.contains("Hello"));   // system.out.println ("contains:" +c.contains ("Android"));  // boolean  IsEmpty (): Determines whether the collection is empty   // system.out.println ("IsEmpty:" +c.isempty ());   //int size () : The number of elements   system.out.println ("Size:" +c.size ());     system.out.println ("C:"  +  C);  }}

Use Notepad to practice, compile the time will report the following such a problem

Note: Collectionxxx.java is using an unchecked or unsafe operation.
Note: To learn more, recompile with-xlint:unchecked. (This is not a compilation failure, not an error!) Knowledge may be an error! )
The Java compiler believes the program has a security risk
Warm tip: This is not a compilation failure, so first ignore, and so learn generics you know

ArrayList this set element can always be successful (because the last sentence of its add source is return true), so it can be said that ArrayList this collection is a repeatable collection

Adding and deleting methods to directly move the set, judging the fixed set

This article from "GD" blog, reproduced please contact the author!

Collection Framework (Basic functional testing of the collection collection)

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.