Solved

What is the easiest way to find the number of occurances of a particular item in an arraylist?

Posted on 2013-06-14
2
199 Views
Last Modified: 2013-06-17
The title says it all.
0
Comment
Question by:NevSoFly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
quizwedge earned 500 total points
ID: 39249495
Two ways to do this. First would be using LINQ. There's a discussion about that at http://www.vbforums.com/showthread.php?674781-Counting-number-of-occurrences-of-element-within-array-or-arraylist

The other way is the manual way is below

Private Function NumberOfInstances(ByVal SearchFor As String, ByVal SearchList As ArrayList) As Integer
        Dim Counter As Integer = 0
        Dim i As Integer
        For i = 0 To SearchList.Count - 1
            If CStr(SearchList(i)) = SearchFor Then
                Counter += 1
            End If
        Next

        Return Counter
    End Function

Open in new window

0
 

Author Closing Comment

by:NevSoFly
ID: 39253045
perfect.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question