Replaces all occurrences of Object obj in list with newObj. If the obj is null, then all occurrences of null are replaced with newObj. @param list the list to modify. @param obj the object to find and replace occurrences
(List<T> list, T obj, T obj2)
| 2021 | * if the list does not support setting elements. |
| 2022 | */ |
| 2023 | public static <T> boolean replaceAll(List<T> list, T obj, T obj2) { |
| 2024 | int index; |
| 2025 | boolean found = false; |
| 2026 | |
| 2027 | while ((index = list.indexOf(obj)) > -1) { |
| 2028 | found = true; |
| 2029 | list.set(index, obj2); |
| 2030 | } |
| 2031 | return found; |
| 2032 | } |
| 2033 | |
| 2034 | /** |
| 2035 | * Rotates the elements in {@code list} by the distance {@code dist} |