ArrayUtils.java 729 B

12345678910111213141516171819202122232425262728293031
  1. package cn.iocoder.dashboard.util.collection;
  2. import cn.hutool.core.util.ArrayUtil;
  3. /**
  4. * Array 工具类
  5. *
  6. * @author 芋道源码
  7. */
  8. public class ArrayUtils {
  9. /**
  10. * 将 object 和 newElements 合并成一个数组
  11. *
  12. * @param object 对象
  13. * @param newElements 数组
  14. * @param <T> 泛型
  15. * @return 结果数组
  16. */
  17. @SafeVarargs
  18. public static <T> T[] append(T object, T... newElements) {
  19. if (object == null) {
  20. return newElements;
  21. }
  22. T[] result = ArrayUtil.newArray(object.getClass(), 1 + newElements.length);
  23. result[0] = object;
  24. System.arraycopy(newElements, 0, result, 1, newElements.length);
  25. return result;
  26. }
  27. }