Array and set, array set

Source: Internet
Author: User

Array and set, array set

Arrays and List sets are used to store data. Today we will talk about the differences between arrays and sets. Array: Data Type [] variable name = new data type [] {}; List set: List <data type> variable name = new list <data type> (); from their writing format, we can see that the length of the array needs to be specified. The length of the array is fixed and cannot be changed, but the List set is not required. The set can be changed to add or delete elements.

Example:

Create an array: int () nums = new int [3]; // specify the length

Int [] nums = {3, 1, 3}; // Variable Length

Create a List set:

List <int> nums = new list <int> (); // The length is not specified.

List <int> nums = new List <int> (2, 1, 6); // Variable Length

In addition, the array occupies less memory, and the traversal speed is fast. The reverse of the set. All functions that the array can implement can be implemented by the set, but the functions that the set can implement are hard to implement by the array.

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.