Solved

arraylist comparison

Posted on 2011-09-09
3
306 Views
Last Modified: 2012-05-12
I had an arraylist with values

DOCX
DOC
DOCX
DOC
DOC
DOC

I want to check whether all the values in the arraylist are equal or not

here the arraylsit values are different (4 DOC 2 DOCX) if different i want to set a flag to false
else set flag to true.

0
Comment
Question by:shragi
[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
3 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36513756
It should be something along the lines of:
Dim baseLine As String = yourArrayList(0).ToString()
Dim allEqual As Boolean = True

For Each item In yourArrayList
    If item.ToString() <> baseLine Then
        allEqual = False
        Exit For
    End If
Next

If allEqual Then
    MessageBox.Show("All items are equal")
Else
    MessageBox.Show("All items are NOT equal")
End If

Open in new window

0
 
LVL 19

Accepted Solution

by:
Shahan Ayyub earned 500 total points
ID: 36513961
Hi!

Have a look at this way:

            bool IsEqual=false;
            ArrayList elements = new ArrayList(new object[] { "DOC", "DOC", "DOC", "DOC", "DOC", "DOC" });
            elements.Sort();
            if (elements[elements.Count - 1] == elements[0])  
                IsEqual = true;

Open in new window

0
 
LVL 19

Assisted Solution

by:Shahan Ayyub
Shahan Ayyub earned 500 total points
ID: 36514038
If you can use LINQ you should look at Distinct() and Count() methods. That would be even more shorter than my previous solution.

This link may help you on that: (where most of the LINQ examples are given)
http://msdn.microsoft.com/en-us/vbasic/bb688085

VB.Net version of my previous solution:
Dim IsEqual As Boolean = False
Dim elements As New ArrayList(New Object() {"DOC", "DOC", "DOC", "DOC", "DOC", "DOC"})
elements.Sort()
If elements(elements.Count - 1) = elements(0) Then
	IsEqual = True
End If

Open in new window

0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

729 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