The difference between Collection and Collections in Java

The difference between Collection and Collections

1. java.util.Collection is a collection interface that provides general interface methods for basic operations of collection objects, such as Set and List collection interfaces. The Collection interface provides a maximized and unified operation mode for various specific collections.

 

Types of:

Collection interface collection

    List subinterface ( ordered, non-repeatable )

           The ArrayList collection class is used to implement data query operations (collection of queue structures)

           The LinkedList collection class is mostly used to implement data addition, deletion, and modification operations (a collection of linked list structures)

           Vector collection class to solve the problem of thread synchronization

                Stack

    Set sub-interface ( unordered, repeatable ) uses iterative method to obtain data, and stores data in hash form

           HashSet collection class

 

Second, java.util.Collections is a wrapper class that contains static polymorphic methods for various collection-related operations. This class cannot be instantiated , just like a tool class , serving the Collection framework in java.

example:

package collectionsProblem;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class TestCollections {
	public static void main(String[] args) {
		//List implements the Collection interface
		List list=new ArrayList();
		double array[]={112,111,23,456,234,564};
		for(int i=0;i<array.length;i++){
			list.add(new Double(array[i]));
		}
		Collections.sort(list);
		for(int i=0;i<array.length;i++){
			System.out.println(list.get(i));
		}
	}
}
/**
 * result:
 * 23.0
111.0
112.0
234.0
456.0
564.0
 */

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326561796&siteId=291194637