二维数组与三维数组

public class Test {

    public static void main(String[] args) {
        // Test.sum();
        // Test.name();
        // Test.Student();
        Test.array();

    }

    public static void sum() {
        Integer[] in = new Integer[] { 1, 33, 22, 44, 3, 5, 35, 65, 64, 66 };
        for (int i = 0; i < in.length; i++) {
            for (int j = 0; j < in.length - 1; j++) {
                Integer s = null;
                if (in[j] > in[j + 1]) {
                    s = in[j + 1];
                    in[j + 1] = in[j];
                    in[j] = s;
                }
            }
        }
        System.out.println(Arrays.toString(in));
    }

    public static void name() {
        Integer[][] in = new Integer[][] { { 1, 2 }, { 7, 8 }, { 1, 4 }, { 6, 2 }, { 5, 8 }, { 1, 6 } };
        for (int i = 0; i < in.length; i++) {
            for (int j = 0; j < in[i].length - 1; j++) {
                Integer[] s = null;
                if (i == in.length - 1) {
                    break;
                } else {
                    if (in[i][j] > in[i + 1][j]) {
                        s = in[i + 1];
                        in[i + 1] = in[i];
                        in[i] = s;
                        break;
                    }
                }
            }
            System.out.println(Arrays.toString(in[i]));
        }
    }

    public static void Student() {
        // List<Student> list = new ArrayList<Student>();
        List<Student> list = new LinkedList<Student>();
        list.add(new Student(3, 4));
        list.add(new Student(3, 5));
        list.add(new Student(5, 7));
        list.add(new Student(6, 3));
        list.add(new Student(4, 6));
        Collections.sort(list, new Comparator<Student>() {

            @Override
            public int compare(Student o1, Student o2) {
                int i = o1.getAge() - o2.getAge();
                if (i == 0) {
                    i = o2.getScore() - o1.getScore();
                }
                return i;
            }

        });
        // Collections.sort(list);
        for (Student student : list) {
            System.out.println("Age" + student.getAge() + "-----" + "Score" + student.getScore());
        }
    }

    public static void array() {
        Integer[][][] arr = new Integer[][][] { { {}, { 223, 22 }, { 222, 33 }, { 2223, 555 } }, { { 7, 8 } },
                { { 1, 2222, 4, 44 } }, { { 6, 2 } } };
        List list = Arrays.asList(arr);
        for (Object object : list) {
            System.out.println(object.toString());
        }
        for (int i = 0; i < arr.length; i++) {
            Integer[] integers = arr[i][0];
            System.out.println(integers);
        }
        for (Iterator iterator = list.iterator(); iterator.hasNext();) {
            Object object = (Object) iterator.next();
            System.out.println(object);
        }

    }

}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值