/** * Remove duplicate Strings from the given array. * Also sorts the array, as it uses a TreeSet. * @param array the String array * @return an array without duplicates, in natural sort order */ public static String[] removeDuplicateStrings(String[] array) { if (Objects.isEmpty(array)) { return array; } Set<String> set = new TreeSet<String>(); for (String element : array) { set.add(element); } return toStringArray(set); }
return toStringArray(tokens);
/** * Merge the given String arrays into one, with overlapping * array elements only included once. * <p>The order of elements in the original arrays is preserved * (with the exception of overlapping elements, which are only * included on their first occurrence). * @param array1 the first array (can be <code>null</code>) * @param array2 the second array (can be <code>null</code>) * @return the new array (<code>null</code> if both given arrays were <code>null</code>) */ public static String[] mergeStringArrays(String[] array1, String[] array2) { if (Objects.isEmpty(array1)) { return array2; } if (Objects.isEmpty(array2)) { return array1; } List<String> result = new ArrayList<String>(); result.addAll(Arrays.asList(array1)); for (String str : array2) { if (!result.contains(str)) { result.add(str); } } return toStringArray(result); }
return toStringArray(result);
/** * 获取多个redis的keys * @param format * @param ids * @return */ public static String[] formatStrings(String format, List<Long> ids) { if (CollectionUtils.isEmpty(ids)) { return null; } List<String> formatList = ids.stream().map( s -> { return String.format(format, s); }).collect(Collectors.toList()); return Strings.toStringArray(formatList); }
/** * Remove duplicate Strings from the given array. * Also sorts the array, as it uses a TreeSet. * @param array the String array * @return an array without duplicates, in natural sort order */ public static String[] removeDuplicateStrings(String[] array) { if (Objects.isEmpty(array)) { return array; } Set<String> set = new TreeSet<String>(); for (String element : array) { set.add(element); } return toStringArray(set); }
/** * Remove duplicate Strings from the given array. * Also sorts the array, as it uses a TreeSet. * @param array the String array * @return an array without duplicates, in natural sort order */ public static String[] removeDuplicateStrings(String[] array) { if (Objects.isEmpty(array)) { return array; } Set<String> set = new TreeSet<String>(); for (String element : array) { set.add(element); } return toStringArray(set); }
return toStringArray(tokens);
return toStringArray(tokens);
/** * Merge the given String arrays into one, with overlapping * array elements only included once. * <p>The order of elements in the original arrays is preserved * (with the exception of overlapping elements, which are only * included on their first occurrence). * @param array1 the first array (can be <code>null</code>) * @param array2 the second array (can be <code>null</code>) * @return the new array (<code>null</code> if both given arrays were <code>null</code>) */ public static String[] mergeStringArrays(String[] array1, String[] array2) { if (Objects.isEmpty(array1)) { return array2; } if (Objects.isEmpty(array2)) { return array1; } List<String> result = new ArrayList<String>(); result.addAll(Arrays.asList(array1)); for (String str : array2) { if (!result.contains(str)) { result.add(str); } } return toStringArray(result); }
/** * Merge the given String arrays into one, with overlapping * array elements only included once. * <p>The order of elements in the original arrays is preserved * (with the exception of overlapping elements, which are only * included on their first occurrence). * @param array1 the first array (can be <code>null</code>) * @param array2 the second array (can be <code>null</code>) * @return the new array (<code>null</code> if both given arrays were <code>null</code>) */ public static String[] mergeStringArrays(String[] array1, String[] array2) { if (Objects.isEmpty(array1)) { return array2; } if (Objects.isEmpty(array2)) { return array1; } List<String> result = new ArrayList<String>(); result.addAll(Arrays.asList(array1)); for (String str : array2) { if (!result.contains(str)) { result.add(str); } } return toStringArray(result); }
return toStringArray(result);
return toStringArray(result);