Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

how to generate random large string in java

// Java program generate a random
// UpperCase or LowerCase or Number String
  
import java.util.*;
  
public class GFG {
  
    static String getAlphaNumericString(int n)
    {
  
        // lower limit for LowerCase Letters
        int lowerLimit = 97;
  
        // lower limit for LowerCase Letters
        int upperLimit = 122;
  
        Random random = new Random();
  
        // Create a StringBuffer to store the result
        StringBuffer r = new StringBuffer(n);
  
        for (int i = 0; i < n; i++) {
  
            // take a random value between 97 and 122
            int nextRandomChar = lowerLimit
                                 + (int)(random.nextFloat()
                                         * (upperLimit - lowerLimit + 1));
  
            // append a character at the end of bs
            r.append((char)nextRandomChar);
        }
  
        // return the resultant string
        return r.toString();
    }
  
    public static void main(String[] args)
    {
        // size of random alphanumeric string
        int n = 20;
  
        // Get and display the alphanumeric string
        System.out.println(getAlphaNumericString(n));
    }
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #generate #random #large #string #java
ADD COMMENT
Topic
Name
7+1 =