[HackerRank] Java Singleton Pattern?
https://www.hackerrank.com/challenges/java-singleton/problem?isFullScreen=true
Solution
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.reflect.*;
class Singleton {
private volatile static Singleton instance;
public static String str;
private Singleton() {}
static Singleton getSingleInstance() {
if (instance == null) {
synchronized (Singleton.class) {
if (instance == null) {
instance = new Singleton();
}
}
}
return instance;
}
}
Leave a comment