?
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
Medium Priority
?
201 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 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

770 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