A concise introduction to collections and arrays

Source: Internet
Author: User

Collections and Array arrays

Arrays can store both the base data type and the object data type, but the length of the array is fixed for cases where the length is clear.

Collection

A collection can store only objects, object types can be different, and are variable in length, for cases where the length is ambiguous, or if the storage object differs

Code practices
Package Com.github.ljmatlight;import java.util.ArrayList;/*** Description: Collections and Arrays* The <br/> Array can store both the base data type and the object data type, but the length of the array is fixed for cases where the length is clear. * <br/> Collection can only store objects, object types may be different, and the length is variable, suitable for cases where the length is ambiguous or the storage object is not. * <br/> author:ljmatlight */ Public classListandarray { Public Static void Main(string[] args) {the//array can store both the base data type and the object data type, but the length of the array is fixed for cases where the length is clear.         int[] Intarray =New int[Ten]; integer[] Integerarray =Newinteger[Ten]; for(inti =0; I <Ten; i++) {Intarray[i] =TenI Integerarray[i] =NewInteger (Ten-i); }intIntarraylength = Intarray.length; for(inti =0; i < intarraylength; i++) {System. out.println("int:"+ i +" = "+ intarray[i]); }intIntegerarraylength = Integerarray.length; for(inti =0; i < integerarraylength; i++) {System. out.println("Integer:"+ i +" = "+ integerarray[i]); }// ===================================================================        The //collection can store only objects, object types can be different, and the length is variable, for cases where the length is ambiguous or the storage object is not. Arraylist<object> objectarraylist =NewArraylist<> (); Objectarraylist.Add("A"); Objectarraylist.Add(1000L); Objectarraylist.Add(false); Objectarraylist.ForEach(O-System. out.println("O = ="+ O)); }}

With the wind floating clouds
Source: Http://www.cnblogs.com/ljmatlight
This article is copyrighted by the author, welcome reprint, but without the consent of the author must retain this paragraph of the statement,
And in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

A concise introduction to collections and arrays

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.