I want to loop through an arraylist to see wheather the p.name(Player name) is equal to what ever the user type in a text-box; when I enter a value it work for the first name but when I change the value in the text-box it throw a concurrent modification error.
Company class
public class Company {
int shares = 100;
ArrayList <Player> shareHolders = new ArrayList<>();
if (condition()) {
for (Player p: company.shareHolders) { // error highlight this line
if (p.name.equalsIgnoreCase(txtname.getText()) &&
(company.shares <= 100 && company.shares >0)) {
company.shares -= Integer.parseInt(txtShares.getText());
p.shares += Integer.parseInt(txtShares.getText());
System.out.println(p.name+":"+p.shares+" | Company"+company.shares);
return;
}else{
company.shareHolders.add(new Player(txtname.getText()));
System.out.println(txtname.getText()+" added");
}
}
}