[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 732
  • 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 FiedererTest Developer/ValidatorCommented:
Pure VB.NET syntax using a loop, or is LINQ OK?
0
 
Tom SageAuthor Commented:
Sure, LINQ is ok.


Thanks
0
 
Jens FiedererTest Developer/ValidatorCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

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

Thank you very much.

0
 
Jens FiedererTest Developer/ValidatorCommented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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