import java.lang.reflect.Array; /** * @author jiaxinyi * @create 2022-10-2813:44 * @email 904531552@qq.com */ class ArraytoString { public <Object> void tostr(Object arr[]){ int length = arr.length; String g="["; for (int i=0;i<length;i++){ g=g+arr[i]+","; } g= g.substring(0, g.length()-1); g=g+"]"; System.out.println(g); } } public class A{ public static void main(String[] args) { Integer[] a=new Integer[]{1,2,3}; System.out.println(a); ArraytoString a1=new ArraytoString(); a1.tostr(a); } }
自定义方法遍历数组
于 2022-10-28 14:18:36 首次发布