zoukankan      html  css  js  c++  java
  • 5.Java中的数组.md

    1.Java的数组定义
    Java中的定义有两种形式:
    type[] arraryName; //推荐形式
    type arrayName[]; //不推荐
    前一种有更好的语义,可读性更好。但是需要注意的是定义数组的时候不能指定长度

    //先定义变量,再赋值
    int[] arrayInt;
    arrayInt = new int[]{1, 2};
     
    //也可以简化定义
    String[] arrayString = {"a"};
     
    //正常的静态初始化
    double[] arrayDouble = new double[]{1, 2}; 
    
    
    

    2.数组错误的获取,在

    try {
        int jjj = arrayInt[100];//越界
         
    }
    catch (ArrayIndexOutOfBoundsException sError) {
        // TODO: handle exception
        System.out.println(sError);
    } 
    
    

    3.数组的内存

    例如下面的代码:

    内存示意图如下:

  • 相关阅读:
    find the most comfortable road
    Rank of Tetris
    Segment set
    Codeforces Round #380 (Div. 2)D. Sea Battle
    A Bug's Life
    Is It A Tree?
    N皇后问题
    符号三角形
    2016 ICPC总结
    Sudoku Killer
  • 原文地址:https://www.cnblogs.com/bugstar/p/8492435.html
Copyright © 2011-2022 走看看