Revision: 63708
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at May 31, 2013 12:40 by borysn
Initial Code
private List<String> initStringList(int maxNumberOfCharacters, int numberOfStrings) { // init place holder for sorted list List<String> list = new ArrayList<>(); for (int i = 0; i < numberOfStrings; i++) { // init a mutable string to add characters to StringBuffer strBuffer = new StringBuffer(); // generate random number 1 - numberOfCharacters int numberOfCharacters = 1 + (int)(Math.random() * ((maxNumberOfCharacters - 1) +1)); // generate random ascii start place between 33 - 100 int asciiStartRand = 33 + (int)(Math.random() * ((100 - 33) + 1)); // going to use initCharacterList(int) to fill strings for (Character c : initCharacterList(numberOfCharacters, asciiStartRand, 126)) { // append characters to String strBuffer.append(c); } // convert to String and add to list list.add(strBuffer.toString()); } // sort list Collections.sort(list); return list; }
Initial URL
Initial Description
Create a List<String> for a specified number strings with a specified max characters (randomized...1-max). This method uses another snippet which contains initCharacterList(int, int) http://snipplr.com/view/71355/fill-character-list-from-ascii-table-and-sort/
Initial Title
Create String List With Random Characters And Sort
Initial Tags
list
Initial Language
Java