比较类似术语之间的差异

Difference Between

家 / Technology / IT / 编程 /Difference Between List and Set

Difference Between List and Set

March 5, 2018Posted byLithmee

关键区别 - 列表与Set

大多数编程语言使用arrays存储一组相同类型的数据。数组的一个主要缺点是,一旦声明了数组大小,就无法修改。如果程序员想存储超过数组大小的值,则他应创建一个新数组,并将现有元素复制到新数组。在这些情况下,可以使用集合。可以在收藏的支持下添加元素,删除元素和许多其他操作。编程语言中有不同类型的收藏,例如Java. List and Set are interfaces of collections hierarchy. The base interface for other interfaces is Collection. Thekey difference在列表和集合之间列表支持多次存储相同的元素,而设置不支持多次存储相同的元素。这refore, a Set does not allow duplication.

内容

1.Overview and Key Difference
2.什么is List
3.设置了什么
4.Similarities Between List and Set
5.Side by Side Comparison – List vs Set in Tabular Form
6.概括

什么is List?

列表是界面that extends the Collection interface. There is a number of methods in Collection interface. The add method helps to add an element. The ‘remove method’ is to remove an element. There is ‘addAll method’ to add multiple elements while ‘removeAll method’ to remove the elements from the collection. The contains method helps to find whether a specific object is present in the List or not. The ‘containsAll’ is to find whether a set of objects are present in the collection. Theiteratormethod is used to loop through the items of the list. As List extends Collection, all the methods of Collection belong to List. Other than those methods, the List has methods such as get and set. The programmer can get a value at a specific index using get method. The programmer can set a value at a specific index using the set method. The ‘indexOf’ is used to find the index of an element.

In a List, the operations can be performed according to the position. The programmer can provide the data element that is to be added to the index. So it will be added to the specific index. If the programmer does not give an index, the element will be added to the end of the List. It also maintains the inserted order. If element 1 is added and then element2 is added, then element1 will be before element2.

Difference Between List and Set

图01:列表并设置

ArrayList, LinkedList,Vector are some classes that implement List. In an ArrayList, accessing an element is fast but inserting and deleting is lower. ArrayList is not thread-safe. Accessing the same ArrayList from multiple threads might not give the same result. In a LinkedList, the elements are linked to both backward and forward. Inserting and deleting elements using a LinkedList is faster than the ArrayList. The LinkedList implements List and Queue Both. Vector is similar to ArrayList, but it is tread-safe because all the methods are synchronized.

什么设置?

集合是一个扩展集合接口的接口。随着SET接口扩展集合,所有集合方法也属于SET。一组不支持重复值。因此,程序员不能两次存储相同的元素。它保持了一组独特的元素。排序集接口扩展了设置接口。SortedSet按顺序保持元素。Navigableset接口扩展了排序集。Navigableset提供导航方法,例如较低,地板,天花板等。

HashSet,LinkedHashset和Treeet是实现集合接口的一些类。这HashSetimplements Set interface. It does not maintain the inserted order. If the values are inserted as a,x,b it might store as, x,a,b. TheLinkedSet保持插入的顺序。如果将元素插入A,X,B顺序,则存储顺序为A,X,B。这TreeSet实施设置和Navigableset。它不能保持插入顺序,而是按顺序存储元素。如果插入顺序为A,C,B,则将元素存储为A,B,C。所有哈希集,LinkedHashset和Treeset都不会具有任何重复元素。

什么are the Similarities Between List and Set?

  • 列表和集合接口扩展了集合接口。
  • Both List and Set support operations such as adding, removing elements.

什么is the Difference Between List and Set?

List vs Set

列表接口是集合的子接口,其中包含根据索引执行操作的方法,例如插入,删除。 Set Interface is a sub interface of Collection that contains methods to perform operations such as insert, delete elements while maintaining the unique elements.
Classes
ArrayList, Vector, and LinkedList are classes that implement List interface. HashSet, LinkedHashSet, and TreeSet are classes that implement Set interface.
元素重复
List supports duplication of elements. Set does not support duplication of elements. Elements are unique.

概括–List vsSet

Collections are used to store elements dynamically. Programming languages such as Java provides Collection interface. List and Set are two interfaces which belong to Collection interface. Both interfaces extend Collection. This article discussed the difference between List and Set. The key difference between List and Set is that List supports storing the same element multiple times while Set does not support storing the same element multiple time. Set always maintains unique elements.

Reference:

1.点,教程。“ Java收藏。”,教程点, 8 Jan. 2018.Available here

Related posts:

清单和元组之间的区别清单和元组之间的区别 Difference Between Randomized and Recursive Algorithm Difference Between Phase and Pass in Compiler Difference Between Subset and Superset getC和getChar_figure 02之间的区别GETC和GETCHAR之间的区别

Filed Under:编程标记为:Compare List and Set,List,List and Set Differences,List and Set Similarities,List Classes,List Definition,列表复制,List vs Set,set,Set Classes,Set Definition,Set Duplication

About the Author:Lithmee

Lithmee Mandula是计算机系统工程的孟加(荣誉)。她目前正在攻读计算机科学硕士学位。她在写作和研究方面的兴趣领域包括编程,数据科学和计算机系统。

发表评论取消回复

Your email address will not be published.Required fields are marked*

请求文章

Featured Posts

Difference Between Coronavirus and Cold Symptoms

Difference Between Coronavirus and Cold Symptoms

冠状病毒和SARS之间的差异

冠状病毒和SARS之间的差异

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Influenza

Difference Between Coronavirus and Covid 19

Difference Between Coronavirus and Covid 19

你可能喜欢

Difference Between Monument and Memorial

Difference Between Monument and Memorial

Difference Between Liquidated Damages and Penalty

Difference Between Central and Peripheral Tolerance

Difference Between Central and Peripheral Tolerance

Difference Between Adipic Acid and Salicylic Acid

Difference Between Adipic Acid and Salicylic Acid

Difference Between iOS 4.2.8 and 4.2.9

Latest Posts

  • 什么is the Difference Between Prevention and Cure
  • 什么is the Difference Between DSM IV and DSM V Autism
  • 分子公式和结构公式之间有什么区别
  • 什么is the Difference Between Acne and Eczema
  • 什么is the Difference Between Mutation Rate and Substitution Rate
  • 什么is the Difference Between Vermicompost and Compost
  • 家
  • Vacancies
  • About
  • 请求文章
  • 联系我们

Copyright © 2010-2018Difference Between. All rights reserved.Terms of Use和隐私政策:合法的.