83rd: The implementation of the list in Scala Insider source code disclosure

Source: Internet
Author: User

Today we will learn some knowledge of the internal source code of the Scala list method.

First, take the method. The Take method is the first n elements of the list that start at the beginning of the second element. For example, List.take (3), which is the first 3 elements of the list, returns a list of the top 3 elements of the list. The principle is to take the head of the list in turn, add the head to a temporary listbuffer, and then take the head of the list of tail. Until you have taken enough of the numbers. Finally, the temporary listbuffer is converted to list by the ToList method.

By the way, look at the ToList method. The ToList method is to convert the Listbuffer into a list. This conversion does not copy all of the elements in the Listbuffer all over, but only the last element of the operation. And it's not going to take much time, it's a very fast thing to do.

Finally, let's take a look at Listbuffer's + = method. The + = method is to append the list to the element. So after we've tolist, we're not going to do any more additions, which will copy the list, consuming time and resources.

Share more of the Scala resources:

Baidu Cloud Disk: http://pan.baidu.com/s/1gd7133t

Micro Cloud Disk: http://share.weiyun.com/047efd6cc76d6c0cb21605cfaa88c416

360 Cloud Disk: Http://yunpan.cn/cQN9gvcKXe26M (extract code: 13CD)

Information from DT Big Data Dream Factory public account: Dt_spark

Follow the account for more information about Scala learning

83rd: The implementation of the list in Scala Insider source code disclosure

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.