在另一个方法中调用带有参数的方法

如何调用另一个方法中具有参数的方法?



    public class StackOverflow {

        static String blackListInput = "*[]#$";


        public static boolean isBlackList(String val) {

            if (val == null) {

                return false;

            }

            for (int i = 0; i < val.length(); i++) {

                if (blackListInput.indexOf(val.charAt(i)) < 0) {

                    return true;

                }

            }

            return false;

        }

        public static boolean cleanseInput() {

            if (isBlackList(val))

                return true;

            return false;

        }

    }


梵蒂冈之花
浏览 85回答 2
2回答

慕森王

尝试这个&nbsp; &nbsp; &nbsp;public class StackOverflow {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; static String blackListInput = "*[]#$";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; static char c[] = {'*','[',']','#','$'};&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public static boolean isBlackList(String val) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if("".equals(val) || val == null) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(val.contains(Character.toString(c[0]))) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(val.contains(Character.toString(c[1]))) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(val.contains(Character.toString(c[2]))) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(val.contains(Character.toString(c[3]))) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(val.contains(Character.toString(c[4]))) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public static boolean&nbsp; cleanseInput(String val) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(isBlackList(val))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public static void main(String[] args) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; boolean b = cleanseInput("*");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(b);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }

qq_笑_17

如果你想使用正则表达式模式&nbsp; &nbsp; import java.util.regex.Matcher;&nbsp; &nbsp; import java.util.regex.Pattern;&nbsp; &nbsp; public class RegexPattern {&nbsp; &nbsp; &nbsp; &nbsp; public static boolean isBlackList(String value) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String regex = "[a-zA-Z0-9\\-#\\*\\[\\]\\$\\s]{0,30}";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pattern p = Pattern.compile(regex);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Matcher m = p.matcher(value);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; boolean b = m.matches();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return b;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public static boolean&nbsp; cleanseInput(String val) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(isBlackList(val))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public static void main(String[] args) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; boolean b = cleanseInput("fsa$assdhsahdfjfjkf");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(b);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java