From 54933ac3ac182bdd1c5991714120d9dd08c27a5c Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Tue, 21 Feb 2017 20:27:19 +0800 Subject: [PATCH] =?UTF-8?q?Utility=E5=A2=9E=E5=8A=A0=20=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=8E=89=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=95=B0=E7=BB=84=E4=B8=AD?= =?UTF-8?q?=E5=8C=85=E5=90=AB=E6=8C=87=E5=AE=9A=E7=9A=84=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/redkale/util/Utility.java | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/org/redkale/util/Utility.java b/src/org/redkale/util/Utility.java index a9e842d60..d0a6e3a6d 100644 --- a/src/org/redkale/util/Utility.java +++ b/src/org/redkale/util/Utility.java @@ -128,6 +128,44 @@ public final class Utility { return UUID.randomUUID().toString().replace("-", ""); } + /** + * 删除掉字符串数组中包含指定的字符串 + * + * @param columns 待删除数组 + * @param cols 需排除的字符串 + * + * @return 新字符串数组 + */ + public static String[] remove(final String[] columns, final String... cols) { + if (columns == null || columns.length == 0 || cols == null || cols.length == 0) return columns; + int count = 0; + for (String column : columns) { + boolean flag = false; + for (String col : cols) { + if (column != null && column.equals(col)) { + flag = true; + break; + } + } + if (flag) count++; + } + if (count == 0) return columns; + if (count == columns.length) return new String[0]; + final String[] newcols = new String[columns.length - count]; + count = 0; + for (String column : columns) { + boolean flag = false; + for (String col : cols) { + if (column != null && column.equals(col)) { + flag = true; + break; + } + } + if (!flag) newcols[count++] = column; + } + return newcols; + } + /** * 将buffer的内容转换成字符串, string参数不为空时会追加在buffer内容字符串之前 *