使用二进制搜索检查字符串是否已在字符串[]中。
//package com.nowjava; /** from * NowJava.com - 时代Java **/ public class Main { public static void main(String[] argv) throws Exception { String s1 = "nowjava.com"; String[] arr = new String[] { "1", "abc", "level", null, "nowjava.com", "asdf 123" }; System.out.println(duplicateInsertion(s1, arr)); } /** * Uses binary searching to check if a String is already in a String[]. * Upper and lower case words that are the same are considered duplicates. * ie Hat and hat are duplicates. * @param s1 * @param arr * @return */ private static boolean duplicateInsertion(String s1, String[] arr) { for (String s