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
Solved

Best way to remove empty elements from ArrayList?

Posted on 2010-09-07
6
720 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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