How to convert String object to Boolean Object?

前端 未结 14 793
我寻月下人不归
我寻月下人不归 2020-11-28 01:28

How to convert String object to Boolean object?

14条回答
  •  [愿得一人]
    2020-11-28 02:23

    Beside the excellent answer of KLE, we can also make something more flexible:

    boolean b = string.equalsIgnoreCase("true") || string.equalsIgnoreCase("t") || 
            string.equalsIgnoreCase("yes") || string.equalsIgnoreCase("y") || 
            string.equalsIgnoreCase("sure") || string.equalsIgnoreCase("aye") || 
            string.equalsIgnoreCase("oui") || string.equalsIgnoreCase("vrai");
    

    (inspired by zlajo's answer... :-))

提交回复
热议问题