@Test public final void testGenerateRandomString() { Assert.assertEquals("", StringUtil.generateRandomString(0)); Assert.assertEquals("", StringUtil.generateRandomString(-1)); Assert.assertEquals(7, StringUtil.generateRandomString(7).length()); Assert.assertFalse(StringUtil.isEmpty(StringUtil.generateRandomString(3))); }
public static String generateRandomString(final int length) { final char[] values = {'a','b','c','d','e','f','g','h','i','j', 'k','l','m','n','o','p','q','r','s','t', 'u','v','w','x','y','z','0','1','2','3', '4','5','6','7','8','9','A','B','C','D', 'E','F','G','H','I','J','K','L','M','N', 'O','P','Q','R','S','T','U','V','W','X', 'Y','Z'}; String out = ""; for (int i=0;i<length;i++) { final int idx=random.nextInt(values.length); out += values[idx]; } return out; }
StringUtil { public static String generateRandomString(final int length) { final char[] values = {'a','b','c','d','e','f','g','h','i','j', 'k','l','m','n','o','p','q','r','s','t', 'u','v','w','x','y','z','0','1','2','3', '4','5','6','7','8','9','A','B','C','D', 'E','F','G','H','I','J','K','L','M','N', 'O','P','Q','R','S','T','U','V','W','X', 'Y','Z'}; String out = ""; for (int i=0;i<length;i++) { final int idx=random.nextInt(values.length); out += values[idx]; } return out; } }
StringUtil { public static String generateRandomString(final int length) { final char[] values = {'a','b','c','d','e','f','g','h','i','j', 'k','l','m','n','o','p','q','r','s','t', 'u','v','w','x','y','z','0','1','2','3', '4','5','6','7','8','9','A','B','C','D', 'E','F','G','H','I','J','K','L','M','N', 'O','P','Q','R','S','T','U','V','W','X', 'Y','Z'}; String out = ""; for (int i=0;i<length;i++) { final int idx=random.nextInt(values.length); out += values[idx]; } return out; } private  StringUtil(); }
StringUtil { public static String generateRandomString(final int length) { final char[] values = {'a','b','c','d','e','f','g','h','i','j', 'k','l','m','n','o','p','q','r','s','t', 'u','v','w','x','y','z','0','1','2','3', '4','5','6','7','8','9','A','B','C','D', 'E','F','G','H','I','J','K','L','M','N', 'O','P','Q','R','S','T','U','V','W','X', 'Y','Z'}; String out = ""; for (int i=0;i<length;i++) { final int idx=random.nextInt(values.length); out += values[idx]; } return out; } private  StringUtil(); static boolean isEmpty(final String obj); static boolean compareNullableStrings(final String str1,
			final String str2); static String replace(final String text, final String searchString, final String replacement); static String replace(final String text, final String searchString, final String replacement, int max); static String escapeSql(String str, final boolean escapeForLike); static byte[] convertHexToArray(final String s); static String toFixedString(final int value, final int length); static String removeHTMLTags(final String html); static int convertToInt(final String str, final int defValue); static long convertToLong(final String str, final long defValue); static double convertToDouble(final String str, final double defValue); static Float convertToFloat(final String str, final Float defValue); static String generateRandomString(final int length); @SuppressWarnings("restriction") static String getEncryptedPassword(final String clearTextPassword); @SuppressWarnings("restriction") static String encrypt(final String userId); @SuppressWarnings("restriction") static String decrypt(final String encryptKey); static List<String> parseCsvLine(final String csvLine); static List<String> parseCsvLine(final String csvLine, 
    									final char separator, final char quotechar, 
    									final char escape, final boolean strictQuotes); static final String explode(final char separator, final String[] input); static final String[] splitSafe(String word, String regex); }
StringUtil { public static String generateRandomString(final int length) { final char[] values = {'a','b','c','d','e','f','g','h','i','j', 'k','l','m','n','o','p','q','r','s','t', 'u','v','w','x','y','z','0','1','2','3', '4','5','6','7','8','9','A','B','C','D', 'E','F','G','H','I','J','K','L','M','N', 'O','P','Q','R','S','T','U','V','W','X', 'Y','Z'}; String out = ""; for (int i=0;i<length;i++) { final int idx=random.nextInt(values.length); out += values[idx]; } return out; } private  StringUtil(); static boolean isEmpty(final String obj); static boolean compareNullableStrings(final String str1,
			final String str2); static String replace(final String text, final String searchString, final String replacement); static String replace(final String text, final String searchString, final String replacement, int max); static String escapeSql(String str, final boolean escapeForLike); static byte[] convertHexToArray(final String s); static String toFixedString(final int value, final int length); static String removeHTMLTags(final String html); static int convertToInt(final String str, final int defValue); static long convertToLong(final String str, final long defValue); static double convertToDouble(final String str, final double defValue); static Float convertToFloat(final String str, final Float defValue); static String generateRandomString(final int length); @SuppressWarnings("restriction") static String getEncryptedPassword(final String clearTextPassword); @SuppressWarnings("restriction") static String encrypt(final String userId); @SuppressWarnings("restriction") static String decrypt(final String encryptKey); static List<String> parseCsvLine(final String csvLine); static List<String> parseCsvLine(final String csvLine, 
    									final char separator, final char quotechar, 
    									final char escape, final boolean strictQuotes); static final String explode(final char separator, final String[] input); static final String[] splitSafe(String word, String regex);  }