Here you can find the source of randomCase(String input)
Parameter | Description |
---|---|
input | a parameter |
public static String randomCase(String input)
//package com.java2s; import java.util.concurrent.ThreadLocalRandom; public class Main { /**/* w ww.j a v a 2 s.co m*/ * Flips the case of some characters in the input (about 50% of characters). * * @param input * @return */ public static String randomCase(String input) { if (input != null) { StringBuilder output = new StringBuilder(); for (int i = 0; i < input.length(); ++i) { char c = input.charAt(i); if (Character.isAlphabetic(c) && ThreadLocalRandom.current().nextDouble() < 0.5) { if (Character.isLowerCase(c)) output.append(Character.toUpperCase(c)); else if (Character.isUpperCase(c)) output.append(Character.toLowerCase(c)); } else output.append(c); } return output.toString(); } else return null; } }