Removing spaces from an ArrayList

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mr Smiggins
    New Member
    • Jan 2007
    • 2

    #1

    Removing spaces from an ArrayList

    I'm trying to make a method that removes all cells that are just spaces from an ArrayList. So far I have this:

    Code:
    public ArrayList removeSpace()
    	{
    		Iterator<String> it = array.iterator();
    			while (it.hasNext())
    			{
    				if (it.next().equals(" "))
    				{
    					it.remove();
    				}
    			}
    		return array;
    This unfortunately seems to return a completely empty ArrayList. Any ideas?
    Thanks in advance
  • Mr Smiggins
    New Member
    • Jan 2007
    • 2

    #2
    Well I'm certainly an idiot. It actually worked fine. Always a good idea not to start off with an empty array if you don't want to end up with one.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by Mr Smiggins
      Well I'm certainly an idiot. It actually worked fine. Always a good idea not to start off with an empty array if you don't want to end up with one.
      A very good idea indeed. Good to know that you found the problem yourself.


      Good luck with the rest of it.

      Comment

      Working...