Collections.swap()

public static void swap([List](<https://docs.oracle.com/en/java/javase/26/docs/api/java.base/java/util/List.html>)<?> list, int i, int j)

Swaps the elements at the specified positions in the specified list. (If the specified positions are equal, invoking this method leaves the list unchanged.)

Parameters:list - The list in which to swap elements.i - the index of one element to be swapped.j - the index of the other element to be

swapped.Throws:IndexOutOfBoundsException - if either i or j is out of range (i < 0 || i >= list.size() || j < 0 || j >= list.size()).**Since:**1.4

    public String solution(String my_string, int num1, int num2) {
//        return new StringBuilder(my_string)
//                .replace(num1, num1+1, String.valueOf(my_string.charAt(num2)))
//                .replace(num2, num2+1, String.valueOf(my_string.charAt(num1)))
//                .toString();
        List<String> list = Arrays.stream(my_string.split("")).collect(Collectors.toList());

        Collections.swap(list, num1, num2);
        return String.join("", list);
    }