提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
是Ipad还是Iphone用户代理
/*时代Java*/ //package com.nowjava; import java.util.regex.Pattern; public class Main { public static void main(String[] argv) throws Exception { String userAgent = "nowjava.com"; System.out.println(isIpadOrIphone(userAgent)); } public static boolean isIpadOrIphone(String userAgent) { String browserName = userAgent.toLowerCase(); String ipadRegx = ".*ipad.*"; String iphoneRegx = ".*iphone.*"; if (Pattern.matches(ipadRegx, browserName) || Pattern.matches(iphoneRegx, browserName)) {