Determines whether the List<T> contains elements that match the conditions defined by the specified predicate.
public: bool Exists(Predicate<T> ^ match);
public bool Exists (Predicate<T> match);
member this.Exists : Predicate<'T> -> bool
Public Function Exists (match As Predicate(Of T)) As Boolean
Parameters
- match
- Predicate<T>
The Predicate<T> delegate that defines the conditions of the elements to search for.
Returns
- Boolean
true
if the List<T> contains one or more elements that match the conditions defined by the specified predicate; otherwise, false
.
Exceptions
ArgumentNullException
match
is null
.
Examples
The following example demonstrates the Contains and Exists methods on a List<T> that contains a simple business object that implements Equals.
using System;using System.Collections.Generic;// Simple business object. A PartId is used to identify a part// but the part name can change.public class Part : IEquatable<Part>{ public string PartName { get; set; } public int PartId { get; set; } public override string ToString() { return "ID: " + PartId + " Name: " + PartName; } public override bool Equals(object obj) { if (obj == null) return false; Part objAsPart = obj as Part; if (objAsPart == null) return false; else return Equals(objAsPart); } public override int GetHashCode() { return PartId; } public bool Equals(Part other) { if (other == null) return false; return (this.PartId.Equals(other.PartId)); } // Should also override == and != operators.}public class Example{ public static void Main() { // Create a list of parts. List<Part> parts = new List<Part>(); // Add parts to the list. parts.Add(new Part() { PartName = "crank arm", PartId = 1234 }); parts.Add(new Part() { PartName = "chain ring", PartId = 1334 }); parts.Add(new Part() { PartName = "regular seat", PartId = 1434 }); parts.Add(new Part() { PartName = "banana seat", PartId = 1444 }); parts.Add(new Part() { PartName = "cassette", PartId = 1534 }); parts.Add(new Part() { PartName = "shift lever", PartId = 1634 }); ; // Write out the parts in the list. This will call the overridden ToString method // in the Part class. Console.WriteLine(); foreach (Part aPart in parts) { Console.WriteLine(aPart); } // Check the list for part #1734. This calls the IEquatable.Equals method // of the Part class, which checks the PartId for equality. Console.WriteLine("\nContains: Part with Id=1734: {0}", parts.Contains(new Part { PartId = 1734, PartName = "" })); // Find items where name contains "seat". Console.WriteLine("\nFind: Part where name contains \"seat\": {0}", parts.Find(x => x.PartName.Contains("seat"))); // Check if an item with Id 1444 exists. Console.WriteLine("\nExists: Part with Id=1444: {0}", parts.Exists(x => x.PartId == 1444)); /*This code example produces the following output: ID: 1234 Name: crank arm ID: 1334 Name: chain ring ID: 1434 Name: regular seat ID: 1444 Name: banana seat ID: 1534 Name: cassette ID: 1634 Name: shift lever Contains: Part with Id=1734: False Find: Part where name contains "seat": ID: 1434 Name: regular seat Exists: Part with Id=1444: True */ }}
Imports System.Collections.Generic' Simple business object. A PartId is used to identify a part ' but the part name can change. Public Class Part Implements IEquatable(Of Part) Public Property PartName() As String Get Return m_PartName End Get Set(value As String) m_PartName = Value End Set End Property Private m_PartName As String Public Property PartId() As Integer Get Return m_PartId End Get Set(value As Integer) m_PartId = Value End Set End Property Private m_PartId As Integer Public Overrides Function ToString() As String Return Convert.ToString("ID: " & PartId & " Name: ") & PartName End Function Public Overrides Function Equals(obj As Object) As Boolean If obj Is Nothing Then Return False End If Dim objAsPart As Part = TryCast(obj, Part) If objAsPart Is Nothing Then Return False Else Return Equals(objAsPart) End If End Function Public Overrides Function GetHashCode() As Integer Return PartId End Function Public Overloads Function Equals(other As Part) As Boolean _ Implements IEquatable(Of Part).Equals If other Is Nothing Then Return False End If Return (Me.PartId.Equals(other.PartId)) End Function ' Should also override == and != operators.End ClassPublic Class Example Public Shared Sub Main() ' Create a list of parts. Dim parts As New List(Of Part)() ' Add parts to the list. parts.Add(New Part() With { _ .PartName = "crank arm", _ .PartId = 1234 _ }) parts.Add(New Part() With { _ .PartName = "chain ring", _ .PartId = 1334 _ }) parts.Add(New Part() With { _ .PartName = "regular seat", _ .PartId = 1434 _ }) parts.Add(New Part() With { _ .PartName = "banana seat", _ .PartId = 1444 _ }) parts.Add(New Part() With { _ .PartName = "cassette", _ .PartId = 1534 _ }) parts.Add(New Part() With { _ .PartName = "shift lever", _ .PartId = 1634 _ }) ' Write out the parts in the list. This will call the overridden ToString method ' in the Part class. Console.WriteLine() For Each aPart As Part In parts Console.WriteLine(aPart) Next ' Check the list for part #1734. This calls the IEquatable.Equals method ' of the Part class, which checks the PartId for equality. Console.WriteLine(vbLf & "Contains: Part with Id=1734: {0}", parts.Contains(New Part() With { _ .PartId = 1734, _ .PartName = "" _ })) ' Find items where name contains "seat". Console.WriteLine(vbLf & "Find: Part where name contains ""seat"": {0}", parts.Find(Function(x) x.PartName.Contains("seat"))) ' Check if an item with Id 1444 exists. Console.WriteLine(vbLf & "Exists: Part with Id=1444: {0}", parts.Exists(Function(x) x.PartId = 1444)) 'This code example produces the following output: ' ' ID: 1234 Name: crank arm ' ID: 1334 Name: chain ring ' ID: 1434 Name: regular seat ' ID: 1444 Name: banana seat ' ID: 1534 Name: cassette ' ID: 1634 Name: shift lever ' ' Contains: Part with Id=1734: False ' ' Find: Part where name contains "seat": ID: 1434 Name: regular seat ' ' Exists: Part with Id=1444: True ' End SubEnd Class
The following example demonstrates the Exists method and several other methods that use the Predicate<T> generic delegate.
A List<T> of strings is created, containing 8 dinosaur names, two of which (at positions 1 and 5) end with "saurus". The example also defines a search predicate method named EndsWithSaurus
, which accepts a string parameter and returns a Boolean value indicating whether the input string ends in "saurus".
The Find, FindLast, and FindAll methods are used to search the list with the search predicate method, and then the RemoveAll method is used to remove all entries ending with "saurus".
Finally, the Exists method is called. It traverses the list from the beginning, passing each element in turn to the EndsWithSaurus
method. The search stops and the method returns true
if the EndsWithSaurus
method returns true
for any element. The Exists method returns false
because all such elements have been removed.
Note
In C# and Visual Basic, it is not necessary to create the Predicate<string>
delegate (Predicate(Of String)
in Visual Basic) explicitly. These languages infer the correct delegate from context and create it automatically.
using namespace System;using namespace System::Collections::Generic;// Search predicate returns true if a string ends in "saurus".bool EndsWithSaurus(String^ s){ return s->ToLower()->EndsWith("saurus");};void main(){ List<String^>^ dinosaurs = gcnew List<String^>(); dinosaurs->Add("Compsognathus"); dinosaurs->Add("Amargasaurus"); dinosaurs->Add("Oviraptor"); dinosaurs->Add("Velociraptor"); dinosaurs->Add("Deinonychus"); dinosaurs->Add("Dilophosaurus"); dinosaurs->Add("Gallimimus"); dinosaurs->Add("Triceratops"); Console::WriteLine(); for each(String^ dinosaur in dinosaurs ) { Console::WriteLine(dinosaur); } Console::WriteLine("\nTrueForAll(EndsWithSaurus): {0}", dinosaurs->TrueForAll(gcnew Predicate<String^>(EndsWithSaurus))); Console::WriteLine("\nFind(EndsWithSaurus): {0}", dinosaurs->Find(gcnew Predicate<String^>(EndsWithSaurus))); Console::WriteLine("\nFindLast(EndsWithSaurus): {0}", dinosaurs->FindLast(gcnew Predicate<String^>(EndsWithSaurus))); Console::WriteLine("\nFindAll(EndsWithSaurus):"); List<String^>^ sublist = dinosaurs->FindAll(gcnew Predicate<String^>(EndsWithSaurus)); for each(String^ dinosaur in sublist) { Console::WriteLine(dinosaur); } Console::WriteLine( "\n{0} elements removed by RemoveAll(EndsWithSaurus).", dinosaurs->RemoveAll(gcnew Predicate<String^>(EndsWithSaurus))); Console::WriteLine("\nList now contains:"); for each(String^ dinosaur in dinosaurs) { Console::WriteLine(dinosaur); } Console::WriteLine("\nExists(EndsWithSaurus): {0}", dinosaurs->Exists(gcnew Predicate<String^>(EndsWithSaurus)));}/* This code example produces the following output:CompsognathusAmargasaurusOviraptorVelociraptorDeinonychusDilophosaurusGallimimusTriceratopsTrueForAll(EndsWithSaurus): FalseFind(EndsWithSaurus): AmargasaurusFindLast(EndsWithSaurus): DilophosaurusFindAll(EndsWithSaurus):AmargasaurusDilophosaurus2 elements removed by RemoveAll(EndsWithSaurus).List now contains:CompsognathusOviraptorVelociraptorDeinonychusGallimimusTriceratopsExists(EndsWithSaurus): False */
using System;using System.Collections.Generic;public class Example{ public static void Main() { List<string> dinosaurs = new List<string>(); dinosaurs.Add("Compsognathus"); dinosaurs.Add("Amargasaurus"); dinosaurs.Add("Oviraptor"); dinosaurs.Add("Velociraptor"); dinosaurs.Add("Deinonychus"); dinosaurs.Add("Dilophosaurus"); dinosaurs.Add("Gallimimus"); dinosaurs.Add("Triceratops"); Console.WriteLine(); foreach(string dinosaur in dinosaurs) { Console.WriteLine(dinosaur); } Console.WriteLine("\nTrueForAll(EndsWithSaurus): {0}", dinosaurs.TrueForAll(EndsWithSaurus)); Console.WriteLine("\nFind(EndsWithSaurus): {0}", dinosaurs.Find(EndsWithSaurus)); Console.WriteLine("\nFindLast(EndsWithSaurus): {0}", dinosaurs.FindLast(EndsWithSaurus)); Console.WriteLine("\nFindAll(EndsWithSaurus):"); List<string> sublist = dinosaurs.FindAll(EndsWithSaurus); foreach(string dinosaur in sublist) { Console.WriteLine(dinosaur); } Console.WriteLine( "\n{0} elements removed by RemoveAll(EndsWithSaurus).", dinosaurs.RemoveAll(EndsWithSaurus)); Console.WriteLine("\nList now contains:"); foreach(string dinosaur in dinosaurs) { Console.WriteLine(dinosaur); } Console.WriteLine("\nExists(EndsWithSaurus): {0}", dinosaurs.Exists(EndsWithSaurus)); } // Search predicate returns true if a string ends in "saurus". private static bool EndsWithSaurus(String s) { return s.ToLower().EndsWith("saurus"); }}/* This code example produces the following output:CompsognathusAmargasaurusOviraptorVelociraptorDeinonychusDilophosaurusGallimimusTriceratopsTrueForAll(EndsWithSaurus): FalseFind(EndsWithSaurus): AmargasaurusFindLast(EndsWithSaurus): DilophosaurusFindAll(EndsWithSaurus):AmargasaurusDilophosaurus2 elements removed by RemoveAll(EndsWithSaurus).List now contains:CompsognathusOviraptorVelociraptorDeinonychusGallimimusTriceratopsExists(EndsWithSaurus): False */
Imports System.Collections.GenericPublic Class Example Public Shared Sub Main() Dim dinosaurs As New List(Of String) dinosaurs.Add("Compsognathus") dinosaurs.Add("Amargasaurus") dinosaurs.Add("Oviraptor") dinosaurs.Add("Velociraptor") dinosaurs.Add("Deinonychus") dinosaurs.Add("Dilophosaurus") dinosaurs.Add("Gallimimus") dinosaurs.Add("Triceratops") Console.WriteLine() For Each dinosaur As String In dinosaurs Console.WriteLine(dinosaur) Next Console.WriteLine(vbLf & _ "TrueForAll(AddressOf EndsWithSaurus: {0}", _ dinosaurs.TrueForAll(AddressOf EndsWithSaurus)) Console.WriteLine(vbLf & _ "Find(AddressOf EndsWithSaurus): {0}", _ dinosaurs.Find(AddressOf EndsWithSaurus)) Console.WriteLine(vbLf & _ "FindLast(AddressOf EndsWithSaurus): {0}", _ dinosaurs.FindLast(AddressOf EndsWithSaurus)) Console.WriteLine(vbLf & _ "FindAll(AddressOf EndsWithSaurus):") Dim sublist As List(Of String) = _ dinosaurs.FindAll(AddressOf EndsWithSaurus) For Each dinosaur As String In sublist Console.WriteLine(dinosaur) Next Console.WriteLine(vbLf & _ "{0} elements removed by RemoveAll(AddressOf EndsWithSaurus).", _ dinosaurs.RemoveAll(AddressOf EndsWithSaurus)) Console.WriteLine(vbLf & "List now contains:") For Each dinosaur As String In dinosaurs Console.WriteLine(dinosaur) Next Console.WriteLine(vbLf & _ "Exists(AddressOf EndsWithSaurus): {0}", _ dinosaurs.Exists(AddressOf EndsWithSaurus)) End Sub ' Search predicate returns true if a string ends in "saurus". Private Shared Function EndsWithSaurus(ByVal s As String) _ As Boolean Return s.ToLower().EndsWith("saurus") End FunctionEnd Class' This code example produces the following output:''Compsognathus'Amargasaurus'Oviraptor'Velociraptor'Deinonychus'Dilophosaurus'Gallimimus'Triceratops''TrueForAll(AddressOf EndsWithSaurus: False''Find(AddressOf EndsWithSaurus): Amargasaurus''FindLast(AddressOf EndsWithSaurus): Dilophosaurus''FindAll(AddressOf EndsWithSaurus):'Amargasaurus'Dilophosaurus''2 elements removed by RemoveAll(AddressOf EndsWithSaurus).''List now contains:'Compsognathus'Oviraptor'Velociraptor'Deinonychus'Gallimimus'Triceratops''Exists(AddressOf EndsWithSaurus): False
Remarks
The Predicate<T> is a delegate to a method that returns true
if the object passed to it matches the conditions defined in the delegate. The elements of the current List<T> are individually passed to the Predicate<T> delegate, and processing is stopped when a match is found.
This method performs a linear search; therefore, this method is an O(n) operation, where n is Count.
Applies to
See also
- Find(Predicate<T>)
- FindLast(Predicate<T>)
- FindAll(Predicate<T>)
- FindIndex
- FindLastIndex
- BinarySearch
- IndexOf
- LastIndexOf
- TrueForAll(Predicate<T>)
- Predicate<T>
FAQs
What is System Collections generic? ›
Contains interfaces and classes that define generic collections, which allow users to create strongly typed collections that provide better type safety and performance than non-generic strongly typed collections.
How to check if list item exists in C#? ›C# list is a collection of elements of the same type. The elements can be accessed by index. The basic two methods that check the existence of an element or elements in a list are: Contains and Exists . Alternatively, it is also possible to use Count , IndexOf , Find , or Any methods.
What is list <> in C#? ›List in C# is a collection of strongly typed objects. These objects can be easily accessed using their respective index. Index calling gives the flexibility to sort, search, and modify lists if required. In simple, List in C# is the generic version of the ArrayList. This ArrayList comes under System.
How to check if a string exists in a list C#? ›if (myList. Contains(myString)) string element = myList. ElementAt(myList. IndexOf(myString));
What is Google collections used for? ›Collections help you create rich ad and free product listing experiences (such as Shoppable Images) in a simpler way. They can also enrich your product data, which may increase performance and improve the user experience.
How to use list t in Java? ›- Syntax. List<T> list = new ArrayList<T>(); ...
- Description. The T is a type parameter passed to the generic interface List and its implemenation class ArrayList.
- Example. Create the following java program using any editor of your choice. ...
- Output.
We can use the in-built python List method, count(), to check if the passed element exists in the List. If the passed element exists in the List, the count() method will show the number of times it occurs in the entire list. If it is a non-zero positive number, it means an element exists in the List.
How do you check if a value is there in a list? ›Using MATCH Function embedded in ISNUMBER function to check if a value exists in list in excel: Another method of checking if a value exists in a list is to use MATCH Function Embedded in ISNUMBER function.
How do I check if an item is present in a list? ›The most convenient way to check whether the list contains the element is using the in operator. Without sorting the list in any particular order, it returns TRUE if the element is there, otherwise FALSE. The below example shows how this is done by using 'in' in the if-else statement.
What does list () mean? ›The list() function creates a list object. A list object is a collection which is ordered and changeable. Read more about list in the chapter: Python Lists.
How to initialize a list in C#? ›
How to declare and initialize a list in C#? List<string> myList = new List<string>() { "one", "two", "three", };
How do you check if all elements in a list are strings? ›Just use all() and check for types with isinstance() .
How do you check if an element in a list contains a string? ›Using any() to check if string contains element from list. Using any function is the most classical way in which you can perform this task and also efficiently. This function checks for match in string with match of each element of list.
What is the difference between exists and contains in list C#? ›Exists: Determines whether the List<T> contains elements that match the conditions defined by the specified predicate. Contains: Determines whether an element is in the List<T> . List<T>. Exists() checks whether any of the items in the list satisfies a condition (specified as a predicate).
How do I hide a Google collection? ›- On your Android phone or tablet, open the Google app .
- At the bottom, tap Collections.
- Tap the collection you want to open.
- At the top right, tap More Delete Delete.
Just one person creates and manages a Collection, and only that person can post to that Collection. You can follow someone else's Collection to see what they share, but you can't share posts into someone else's Collection.
How do I block Google data collection? ›...
Turn "Do Not Track" on or off
- On your Android device, open the Chrome app .
- To the right of the address bar, tap More. ...
- Tap Privacy and security.
- Tap Do Not Track.
List<T> is a generic class that can be used with the type it is declared with; e.g., List<int> can store int s and list<string> can store string s.
What is generic type for list? ›The List<T> class is the generic equivalent of the ArrayList class. It implements the IList<T> generic interface by using an array whose size is dynamically increased as required. You can add items to a List<T> by using the Add or AddRange methods.
What does list <?> in Java mean? ›In Java, a list interface is an ordered collection of objects in which duplicate values can be stored. Since a List preserves the insertion order, it allows positional access and insertion of elements. List interface is implemented by the following classes: ArrayList.
How do you check if a value exists in a data frame? ›
You can check if a column contains/exists a particular value (string/int), list of multiple values in pandas DataFrame by using pd. series() , in operator, pandas. series. isin() , str.
How do you check if a value already exists in an array of objects? ›You can use the includes() method in JavaScript to check if an item exists in an array. You can also use it to check if a substring exists within a string. It returns true if the item is found in the array/string and false if the item doesn't exist.
How do you check if a value exists in a range of cells? ›In Excel, to check if a value exists in a range or not, you can use the COUNTIF function, with the IF function. With COUNTIF you can check for the value and with IF, you can return a result value to show to the user. i.e., Yes or No, Found or Not Found.
How do you check if all elements in a list are unique? ›Example. # Given List Alist = ['Mon','Tue','Wed','Mon'] print("The given list : ",Alist) # Compare length for unique elements if(len(set(Alist)) == len(Alist)): print("All elements are unique. ") else: print("All elements are not unique. ")
How do you check if a list has a key? ›Using Keys() The keys() function and the "in" operator can be used to see if a key exists in a dictionary. The keys() method returns a list of keys in the dictionary, and the "if, in" statement checks whether the provided key is in the list. It returns True if the key exists; otherwise, it returns False.
How do you check if a value is in a list bash? ›First, we'll substitute the items delimiter with a newline character. Then, we can pipe the list delimited with newlines to grep -F -q -x “$VALUE”. This way, we check if VALUE is on the list or not.
What are the types of lists present? ›- Bucket list. Such as "100 things to do before you die". ...
- TODO list. Such as "Weekend tasks to complete". ...
- Best-of list. Such as "Top 10 movies of all time". ...
- Inventory list. Such as "Items for sale".
- Brainstorming list. Such as this list. ...
- Index list. A list of lists. ...
- Check list. ...
- Timeline list.
An ordered list is marked with the numbers by default. You can create an ordered list using the <ol></ol> tag and, define the list items using <li></li>. type="1"− This creates a numbered list starting from 1. type="A"− This creates a list numbered with uppercase letters starting from A.
How do you find the item in an array list? ›- Using contains() method.
- Using indexOf() method.
a record of short pieces of information, such as people's names, usually written or printed with a single thing on each line and often ordered in a way that makes a particular thing easy to find: a shopping list.
What is a list example? ›
What is a List? A list is an ordered data structure with elements separated by a comma and enclosed within square brackets. For example, list1 and list2 shown below contains a single type of data. Here, list1 has integers while list2 has strings.
What is a list used for? ›2. A list is any information displayed or organized in a logical or linear formation. Below is an example of a numerical list, often used to show several steps that need to be performed to accomplish something.
How to declare list type variable in C#? ›The type of variable that the list can store is defined using the generic syntax. Here is an example of defining a list called numbers which holds integers. List<int> numbers = new List<int>(); The difference between a list and an array is that lists are dynamic sized, while arrays have a fixed size.
What is an example of generic? ›You use generic to describe something that refers or relates to a whole class of similar things. Parmesan is a generic term used to describe a family of hard Italian cheeses. A generic drug or other product is one that does not have a trademark and that is known by a general name, rather than the manufacturer's name.
How to convert generic list to ArrayList in C#? ›string[] array1 = list. ToArray();
How to initialize list in Python? ›- list = [] print (list) list = [1,2,3,4] print (list)
- [] [1,2,3,4]
- list = [i for i in range(5)] print (list)
- [0,1,2,3,4]
- list = [5]*10 print (list)
- [5,5,5,5,5,5,5,5,5,5]
- public string Name { get; set; } public string Surname { get; set; } public int Age { get; set; } public List<Date> dates{ get; set; } = new List<Date>();
- <pre> public class Date { public DateTime date { get; set; } }
There are multiple ways to convert an array to a list in C#. One method is using List. AddRange method that takes an array as an input and adds all array items to a List. The second method is using ToList method of collection.
What are generic & non-generic collections? ›A Generic collection is a class that provides type safety without having to derive from a base collection type and implement type-specific members. A Non-generic collection is a specialized class for data storage and retrieval that provides support for stacks, queues, lists and hash tables.
What are the benefits of generic collections? ›- Type safety. ...
- Less code and code is more easily reused. ...
- Better performance. ...
- Generic delegates enable type-safe callbacks without the need to create multiple delegate classes. ...
- Generics streamline dynamically generated code.
Why generic collections? ›
A generic collection is strongly typed (you can store one type of objects into it) so that we can eliminate runtime type mismatches, it improves the performance by avoiding boxing and unboxing.
What is a System collection? ›System-Collections are special collections which are not editable, deletable or movable. Apart from that they can be used like all other collections.
What are the generic methods? ›Generic methods are methods that introduce their own type parameters. This is similar to declaring a generic type, but the type parameter's scope is limited to the method where it is declared. Static and non-static generic methods are allowed, as well as generic class constructors.
What are different types of collections in coding? ›Collection types represent different ways to collect data, such as hash tables, queues, stacks, bags, dictionaries, and lists. All collections are based on the ICollection or ICollection<T> interfaces, either directly or indirectly.
What is difference between generics and collections? ›Generics is a programming tool to make class-independent tools, that are translated at compile time to class-specific ones. Collections is a set of tools that implement collections, like list and so on.
What is T in Java generics? ›Oct 11, 2021· 3 min read. < T > is a conventional letter that stands for "Type", and it refers to the concept of Generics in Java. You can use any letter, but you'll see that 'T' is widely preferred.
What is generic code? ›Generic programming is a style of computer programming in which algorithms are written in terms of types to-be-specified-later that are then instantiated when needed for specific types provided as parameters.
What is the purpose of a generic function? ›Generic functions are functions declared with one or more generic type parameters. They may be methods in a class or struct , or standalone functions. A single generic declaration implicitly declares a family of functions that differ only in the substitution of a different actual type for the generic type parameter.
Why do we use generic collections in Java? ›Code that uses generics has many benefits over non-generic code: Stronger type checks at compile time. A Java compiler applies strong type checking to generic code and issues errors if the code violates type safety. Fixing compile-time errors is easier than fixing runtime errors, which can be difficult to find.
What is difference between collection and generics in Java? ›Code Reuse: With help of Generics, one needs to write a method/class/interface only once and use it for any type whereas, in non-generics, the code needs to be written again and again whenever needed.
What is the use of generics in collections Java? ›
Generics means parameterized types. The idea is to allow type (Integer, String, … etc., and user-defined types) to be a parameter to methods, classes, and interfaces. Using Generics, it is possible to create classes that work with different data types.