|
@@ -0,0 +1,52 @@
|
|
|
+package com.example.opc_common.util;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class ArrayUtil {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将不带中括号的字符串转为List,且泛型不能为String
|
|
|
+ *
|
|
|
+ * @param str
|
|
|
+ * @param clazz
|
|
|
+ * @param <T>
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static <T> List<T> strToList(String str, Class<T> clazz) {
|
|
|
+ List<T> list = JSON.parseObject(Arrays.asList(str.split(",")).toString(), List.class);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将不带中括号的字符串转为List<String>
|
|
|
+ *
|
|
|
+ * @param str
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<String> strToListstr(String str) {
|
|
|
+ String[] split = str.split(",");
|
|
|
+ int length = split.length;
|
|
|
+ if (length == 0) {
|
|
|
+ //通过判断原来的字符串中含有几个","进行判断他的长度
|
|
|
+ //使用集合进行add,不会丢失长度
|
|
|
+ }
|
|
|
+ return new ArrayList<>(Arrays.asList(str.split(",")));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将集合转换为不带中括号的字符串
|
|
|
+ *
|
|
|
+ * @param list
|
|
|
+ * @param <T>
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static <T> String listToStr(List<T> list) {
|
|
|
+ return StringUtils.join(list, ",");
|
|
|
+ }
|
|
|
+}
|