Solved

Best way to remove empty elements from ArrayList?

Posted on 2010-09-07
6
723 Views
Last Modified: 2012-08-13
I would like to remove multiple empty elements from an ArrayList.

What is the best way to do this?  Would prefer VB.NET syntax. Using VS 20008.

Thanks
0
Comment
Question by:Tom Sage
[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
  • 3
  • 3
6 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 33621826
Pure VB.NET syntax using a loop, or is LINQ OK?
0
 

Author Comment

by:Tom Sage
ID: 33621844
Sure, LINQ is ok.


Thanks
0
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 500 total points
ID: 33621876
Dim query = From student As Student In arrList _
                    Where student is not null _
                    Select student
dim list as new ArrayList(query.ToArray)


Of course, it's best nowadays not to use ArrayList at all.....List<objectType> is usually a better choice.
0
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 

Author Comment

by:Tom Sage
ID: 33621940
Can you give me an example using the List<objectType> ?

Thank you very much.

0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 33621967
After the same first line as above,

query.ToList()

gives you a List<Student>

(the original "arrList" doesn't really have to be an ArrayList, it can be any collection)
0
 

Author Closing Comment

by:Tom Sage
ID: 33621996
jensfiederer - Thanks for the quick response, and the excellent code !!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

696 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