Q:

method to remove users from files

this code can find the client but cant remove it. client name - "rafael"
i just cant remove the client and i dont know why, i tried some codes but didnt work, can you guys help me?
//this delets clients
public void EliminarUtilizador(){
              ArrayList<ArrayList<String>> dados = new ArrayList<ArrayList<String>>();
            dados = _ficheiro.lerDados();
            // the line is an array that haves date stored on the file
            //0-nome 1-pass ...
            for(ArrayList<String> linha : dados){
                Utilizador a = new Utilizador(linha);
                if("Rafael".equals(linha.get(0))){
                    System.out.println("Client found");

                }
            }  
          }

    ----------------------
    //This reads the file

      public ArrayList<ArrayList<String>> lerDados(){
            ArrayList<ArrayList<String>> dados = new ArrayList<ArrayList<String>>();
            Scanner s;
            try{
            s = new Scanner(new File(nomeFicheiro));
            }catch(FileNotFoundException e){
                return dados;
            }
            String dado;

            while(s.hasNextLine()){
                dado = s.nextLine();
                dados.add(new ArrayList<>(Arrays.asList(dado.split(","))));
            }
            s.close();
            return dados;
        }

A:

You need to use iterator to iterator through the list. Once you find the item, you can remove using iterators method. Below is sample code.
List<String> list = new ArrayList<String>();
    Iterator<String> itr  = list.iterator();
    while(itr.hasNext()){
        String str = itr.next();
        //remove item based on some condition.
        itr.remove();
    }

