cancel
Showing results for 
Search instead for 
Did you mean: 

ArrayList - delete all objects

Former Member
0 Kudos

Hi,

just wanted to know how i delete all elements from a class of type "ArrayList".

my code won't work in any way:(.

the ArrayList contains objects of type "login" referenced as loginliste

(left out the not relevant code-parts)


public class LoginBean extends ArrayList {

	Login loginListe;

	public void eraseData() {
	//Deltes all objects within sessionbean
		
		ArrayList tmpCol = new ArrayList();
		
		ListIterator li = this.listIterator();
        while (li.hasNext()) {
        	
        	this.loginListe = (Login)li.next();
        	
        	tmpCol.add(loginListe);
            	
            }
        
        //remove all found elements
        this.removeAll(tmpCol);
        
        }
}

Hope anyone might help

thx

lars

Accepted Solutions (1)

Accepted Solutions (1)

former_member182294
Active Contributor
0 Kudos

Hi,

Need not to struggle that much you can simple use <b>this.clear()</b>

Regards

Abhilash

Former Member
0 Kudos

oouch, java can be so simple

thx a lot Abhilash!

former_member182294
Active Contributor
0 Kudos

Use <a href="http://java.sun.com/j2se/1.4.2/docs/api/">Java API</a> to find out the available functions and usage. It will be more easy for you..

Regards

Abhilash

Answers (1)

Answers (1)

former_member186016
Active Contributor
0 Kudos

Hi,

You are extending ArrayList. It seems you want to create your special list.

Then if you are using

this.removeAll(tmpCol) 

use super() to initialize the parent arraylist instead of

 ArrayList tmpCol = new ArrayList(); 

Well i am still not able to understand your scenario. get you please elaborate a more on what you want to achieve.

Regards,

Ashwani