Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to select a random element from an array in java

import java.util.Random;

public class RandomStringFromArray
{    
  	public static void main(String[] args)    
    {        
      	String[] arr={"1", "2", "3", "4", "5"};
      	Random r=new Random();        
      	int randomNumber=r.nextInt(arr.length);
      	System.out.println(arr[randomNumber]);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java execution time 
Java :: java pause 1 second 
Java :: fullscreen activity android 
Java :: cordova android.useandroidx 
Java :: storage permission android 
Java :: java lambda foreach multiple statements 
Java :: java check if number is even 
Java :: java check if able to parse int 
Java :: swing disable button 
Java :: java get current milliseconds 
Java :: request permission foreground service 
Java :: cast long to string java 
Java :: how to install java on ubuntu 18.0.4 
Java :: jackson ignore null 
Java :: how to print a 2d array in java 
Java :: java bufferedimage get int array 
Java :: java check ipv6 with regex 
Java :: java selenium wait 
Java :: set text size programmatically android 
Java :: java split string into list 
Java :: Java algorithm for drawing a line 
Java :: how to echo java_home in windows cmd 
Java :: finally block does not complete normallyJava(536871096) 
Java :: java contains password input 
Java :: how to resice image button src 
Java :: convert string to char array in java 
Java :: java ee service formparam optional 
Java :: rwegex java 
Java :: java stream to list 
Java :: java remove equal element of a list 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =