⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 java的经典例子
💻 JAVA
字号:
import java.lang.reflect.*;

class Main {
    // Returns an array with the same contents but double in size.
    public static Object expand(Object array) {
        Object result = Array.newInstance(array.getClass().getComponentType(), 
            Array.getLength(array)*2);

        // Copy the old contents to the new array.
        for (int i=0; i<Array.getLength(array); i++) {
            Array.set(result, i, Array.get(array, i));
        }

        // A faster alternative would be
        //System.arraycopy(array, 0, result, 0, Array.getLength(array));

        return result;
    }

    public static void main(String[] args) {
        int[] ints = {5, 4, 6, 9, 1};
        char[] chars = {'j', 'a', 'v', 'a'};

        ints = (int[])expand(ints);
        chars = (char[])expand(chars);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -