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
197 Views
Last Modified: 2013-06-17
The title says it all.
0
Comment
Question by:NevSoFly
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 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