ArrayList

4 respostas
F

Bom Dia, eu não estou conseguindo remover elemetos no ArrayList eu estou usando da seguinte forma:

public void storeNote(String note)
    {
        notes.add(note);
    }

   
    public int numberOfNotes()
    {
        return notes.size();
    }

   public int removeNota()
   {
     
       return notes.remove();
       
    }

Obrigado

4 Respostas

Andre_Fonseca

oi

tenta assim

public boolean removeNota(String note) {

  return notes.remove(note);

}
P
import java.util.ArrayList;

public class ArrayTeste {
	
	public ArrayList<String> notes = new ArrayList<String>();
	
	public static void main(String[] args) {		
		
		ArrayTeste lista = new ArrayTeste();
		lista.storeNote("Jandira");
		lista.storeNote("João");
		lista.storeNote("Maria");
		System.out.println(lista.numberOfNotes());		
		System.out.println(lista.removeNota("Jandira"));
		System.out.println(lista.numberOfNotes());
	}
	
	public void storeNote(String note)
	{
	notes.add(note);
	}


	public int numberOfNotes()
	{
	return notes.size();
	}

	public boolean removeNota(String nome)
	{
	
		return notes.remove(nome);
	} 

}
R

Se você não passar o elemento a remover, o ArrayList não tem como determinar isso por você.

http://java.sun.com/javase/6/docs/api/java/util/ArrayList.html#remove(int)
http://java.sun.com/javase/6/docs/api/java/util/ArrayList.html#remove(java.lang.Object)

F

Deu certo…
muito obrigado

Criado 6 de maio de 2009
Ultima resposta 6 de mai. de 2009
Respostas 4
Participantes 4