不废话,上代码:
package com.jxd; import org.apache.commons.lang3.ArrayUtils; public class TestArr { /** * ArrayUtils 工具操作数组 * <dependency> * <groupId>org.apache.commons</groupId> * <artifactId>commons-lang3</artifactId> * <version>3.7</version> * </dependency> * @param args */ public static void main(String[] args) { String[] arr=new String[]{"a","b","c"}; String[] arr1={"f","g"}; System.out.println("数组合并"); //数组合并 String[] arrall = ArrayUtils.addAll(arr, arr1); for (int i=0;i<arrall.length;i++){ System.out.println(arrall[i]); } System.out.println("数组倒转......"); ArrayUtils.reverse(arr); for (String str: arr ) { System.out.println(str); } System.out.println("数组中元素删除"); arr=ArrayUtils.remove(arr,1); for (String str: arr ) { System.out.println(str); } //ArrayUtils动态添加数组 arr=ArrayUtils.add(arr,"applle"); for (String str: arr ) { System.out.println(str); } }}
原文地址:https://www.cnblogs.com/coderdxj/p/9350263.html
时间: 2024-12-14 06:29:32