Create random String from an array of string - Android java.util

Android examples for java.util:Random String

Description

Create random String from an array of string

Demo Code

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;
import android.text.format.DateFormat;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;

public class Main{

    public static String randomString() {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < 64; i++) {
            int num = random.nextInt(62);
            buf.append(str.charAt(num));
        }/* w ww .ja v a 2 s  .  c  o m*/
        return buf.toString();
    }

}

Related Tutorials