[Solved] Cannot invoke split(String) on the array type String[] [duplicate]


You can’t do split on a list, once you split the string then you have an array of all the IPs then you can check

    // 123.11.1.1, 123.1.1.12, 123.322.12.1
    String[] list = merchant.getAllowed_ip_address().split(",");

    String ip = request.getRemoteAddr();

    for (String allowedIP : list) {
        if (!ip.trim().equals(allowedIP.trim())) {
            // Not in list
        }
    }

Also, you can do this for simplicity

String ip = request.getRemoteAddr();
boolean notExist = Arrays.stream(merchant.getAllowed_ip_address().split(","))
                .map(String::trim)
                .noneMatch(ip::equals);

solved Cannot invoke split(String) on the array type String[] [duplicate]