Solved

Best way to remove empty elements from ArrayList?

Posted on 2010-09-07
6
719 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:MisterT25
  • 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:MisterT25
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:MisterT25
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:MisterT25
ID: 33621996
jensfiederer - Thanks for the quick response, and the excellent code !!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 (3.5 Framework) Remove all items from List 3 22
C# bracket error 3 30
Expression Evaluater 3 24
vb.net and creating a class 5 15
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 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