ArrayUtils.java 803 B

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