Advertisement
Guest User

Untitled

a guest
Aug 8th, 2022
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1.     private static final Set<String> trueSet = new HashSet<String>(Arrays.asList("1", "true", "yes"));
  2.     private static final Set<String> falseSet = new HashSet<String>(Arrays.asList("0", "false", "no"));
  3.     public static boolean stringToBool(String s) {
  4.         s = s.toLowerCase();
  5.  
  6.         if (trueSet.contains(s))
  7.             return true;
  8.         if (falseSet.contains(s))
  9.             return false;
  10.  
  11.         throw new IllegalArgumentException(s + " is not a boolean.");
  12.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement