Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 729
  • Last Modified:

Best way to remove empty elements from ArrayList?

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
Tom Sage
Asked:
Tom Sage
  • 3
  • 3
1 Solution
 
Jens FiedererCommented:
Pure VB.NET syntax using a loop, or is LINQ OK?
0
 
Tom SageAuthor Commented:
Sure, LINQ is ok.


Thanks
0
 
Jens FiedererCommented:
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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
Tom SageAuthor Commented:
Can you give me an example using the List<objectType> ?

Thank you very much.

0
 
Jens FiedererCommented:
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
 
Tom SageAuthor Commented:
jensfiederer - Thanks for the quick response, and the excellent code !!
0

Featured Post

Industry Leaders: 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!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now