Created
May 20, 2018 15:00
-
-
Save ThanawatMas/caa59452414f4d3c3b4282d30c18f228 to your computer and use it in GitHub Desktop.
SolveByCopyOnWriteArrayList.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SolveByCopyOnWriteArrayList extends ConcurrentModificationSolution { | |
@Override | |
public void addItemAndReIndex(List<String> roundItem, String newItem) { | |
List<String> copyRoundItem = new CopyOnWriteArrayList<>(roundItem); | |
for(String item: copyRoundItem) { | |
if(item.equals(newItem)) { | |
roundItem.remove(item); | |
} | |
} | |
roundItem.add(0, newItem); | |
} | |
@Override | |
public String solutionName() { | |
return "CopyOnWriteArrayList"; | |
} | |
public static void main(String[] args) { | |
SolveByCopyOnWriteArrayList copyOnWriteArrayList = new SolveByCopyOnWriteArrayList(); | |
copyOnWriteArrayList.solve(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment