Replacing Elements in Collections Both the List<E> interface and the Collections class define a replaceAll() method to replace elements in…