VB.Net program to check the specified item is exits in the Queue collection or not

Here, we are going to learn how to check the specified item is exits in the Queue collection or not in VB.Net?
Submitted by Nidhi, on January 17, 2021 [Last updated : March 08, 2023]

Check an item exists in a Queue in VB.Net

Here, we will use the Contains() method of the Queue collection class. This method returns a Boolean value, if the specified item exists in Queue collection then return "True" otherwise it returns "False".

Program/Source Code:

The source code to check the specified item exists in the Queue collection or not is given below. The given program is compiled and executed successfully.

VB.Net code to check an item exists in a Queue

'VB.Net program to check the specified item exists 
'in the Queue collection or not.

Imports System
Imports System.Collections

Module Module1
    Sub Main()

        Dim queue As New Queue(5)

        queue.Enqueue("India")
        queue.Enqueue("USA")
        queue.Enqueue("UK")
        queue.Enqueue("CHINA")

        If (queue.Contains("India")) Then
            Console.WriteLine("Item exists in queue")
        Else
            Console.WriteLine("Item does not exist in queue")
        End If
    End Sub
End Module

Output

Item exists in queue
Press any key to continue . . .

Explanation

In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program, And, we created an object of the Queue collection class for 5 elements. After that, we inserted 4 items using the Enqueue() method and then check the item "India" exists in the Queue collection using Contains() method then print the "Item exists in queue" message on the console screen.

VB.Net Data Structure Programs »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.