package com.santhosh.random;
import java.util.Random;
import org.apache.commons.lang3.StringUtils;
public class SequenceGenerator {
private final Random random;
public SequenceGenerator() {
random = new Random();
}
/**
* Returns a pseudo-random integer between 0 and n-1.
*
* @see Random#nextInt(int)
*/
public int nextInt(int n) {
return random.nextInt(n);
}
public static void main(String[] args) {
SequenceGenerator g = new SequenceGenerator();
String result = StringUtils.leftPad(String.valueOf(g.nextInt(99999)),
5, '0');
System.out.println(result);
}
}
hashCode and equals methods in java
Usage of hashCode() and equals()hashCode() method returns integer for a given object. This integer is used for determining the bucket location, when this object needs to be stored in some HashTable like data structure. By default, Object’s hashCode() method returns an integer representation of memory address where object is stored. equals() method is used to…