Sometimes you need to scramble a String in Java - perhaps you're writing an anagram programme. You can do this by treating the input string as a List of String. The code file is HERE


import java.util.*;

public class Scramble {

    public static void main(String[] args) {
        System.out.printf("'%s'\n", Scramble.getScrambled(args[0]));

    public static String getScrambled(String s) {
        String[] scram = s.split("");
        List<String> letters = Arrays.asList(scram);
        StringBuilder sb = new StringBuilder(s.length());
        for (String c : letters) {
        return sb.toString();

Please support this site using the button below: