Java的数组
来源:互联网 发布:孕囊数据看男女已验证 编辑:程序博客网 时间:2024/05/29 03:21
我们知道,在Java中,数组也是一种对象,所以,数组应该也存储在堆区中。
既然数组是一种对象,那么它也应该有相应的方法和属性,通过IDE的帮助,我们可以得到以下方法:
根据猜测,数组应该直接继承Object类,并且复写了clone方法(测试过,应该是浅复制)。但是没有复写finalize方法(所以一共也就只有10种方法)
属性只有一个,即length,表明该数组的元素大小。
数组和集合的转换:
如果想把集合转换成数组,可以通过接口List的toArray方法进行。
/** * Returns an array containing all of the elements in this list in proper * sequence (from first to last element). * * <p>The returned array will be "safe" in that no references to it are * maintained by this list. (In other words, this method must * allocate a new array even if this list is backed by an array). * The caller is thus free to modify the returned array. * * <p>This method acts as bridge between array-based and collection-based * APIs. * * @return an array containing all of the elements in this list in proper * sequence * @see Arrays#asList(Object[]) */ Object[] toArray();
数组转换成集合。
Arrays.asList(T... t);
/** * Returns a fixed-size list backed by the specified array. (Changes to * the returned list "write through" to the array.) This method acts * as bridge between array-based and collection-based APIs, in * combination with {@link Collection#toArray}. The returned list is * serializable and implements {@link RandomAccess}. * * <p>This method also provides a convenient way to create a fixed-size * list initialized to contain several elements: * <pre> * List<String> stooges = Arrays.asList("Larry", "Moe", "Curly"); * </pre> * * @param a the array by which the list will be backed * @return a list view of the specified array */ @SafeVarargs public static <T> List<T> asList(T... a) { return new ArrayList<>(a); }
- java的类数组
- 说说java的数组
- Java 数组 的 拷贝
- java数组的赋值
- java的数组问题
- java数组的复制
- java数组的定义
- Java数组的学习
- java数组的问题
- JAVA数组的排序
- JAVA数组的替换
- java数组的应用
- Java 数组的拷贝
- java 数组的排序
- 七、java的数组
- Java当中的数组
- java的数组
- java的数组(2)
- NYOJ-420:p次方求和
- C#操作Excel文件
- 陶仁贤学习笔记5
- 解决挂载ramdisk时Failed to execute /linuxrc.问题
- uboot之nandflash相关程序解释
- Java的数组
- flv在线录制、视频转换网站开发文档
- Android设计模式 — 观察者模式
- 硬件访问与混杂设备驱动
- 什么是反向代理
- 关于电商软件市场的格局点评
- poj 3486 简单dp
- Google地图API——IP映射为地址
- 2013年浙江某三甲医院的事业单位考试(信息科)笔试和面试