exception - ConcurrentModificationException in java calculator -


i have problem in calculator tried made. first must idea, idea first separate in arraylist, example:

[12, +, (, 236, -, 7, ×, 23, ), +, 5!, -, 3, ^, 5] 

next remove part of list , replace 1 number, if used previous example:

[12, +, (, 236, -, 7, ×, 23, ), +, 5!, -, 3, ^, 5] ->  [12, +, 215, +, 5!, -, 3, ^, 5] ->  [12, +, 215, +, 120, -, 243] , on.. 

but have problem. way calculate [3, ^, 5] is: first check if there ^ in arraylist loop, , make 2 variables 1 index of first number 0 has value of 3 , 1 2 has value of 5, make third variable answer, after turn answer double string, , remove 3, ^ , 5 list , add answer in of first number 3 0, problem when try turn answer string exception happen (concurrentmodificationexception), searched , discovered because reason can't turn variable type type in situation in. want know reason , how fix it.

your problem trying modify arraylist while iterating in loop wrong, can use iterator.remove if need delete values list, if need add new values - use instance of arraylist


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -