?
Solved

Best way to remove empty elements from ArrayList?

Posted on 2010-09-07
6
Medium Priority
?
725 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 2000 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

801 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