我想知道数组的缺点是什么。我认为知道数组是否是在特定情况下存储数据的最佳方式,或者预测执行的时间,是非常有帮助的。
编辑1:澄清,根据我的理解,由数组:
E 211。1或更多索引用于引用(特定的数据容器)。包含的primitive.E 247 is E 148快速E 249 operationE 154慢速E 255操作,as数组是recreatedElement类型Element类型E 259是在运行时执行的E 160强制E 261,这称为数组是reified.Java数组方法在java.util.Arrays中,而您的方法甚至不包含基本的数组操作方法,如、union、和intersection.。令人遗憾的是,番石榴库不是标准Java.对象数组的一部分,其中填充了引用,以指向数据实际上是的存储位置。
数组的
Array 被称为二维数组。2d数组第一个数组中填充了对其他数组的引用。其他数组不存储的sequentially.Other数组可以在元素大小上有所变化,这被称为ragged-和锯齿arrays.Java数组有行主要的order.Array 维度通常被限制为255E 2106,但它与implementation.不同。
Exceptions和重要笔记。1. In case of managed memory environment, the **absolute locations** of data elements **can be sequential**, but most likely are not.
2. Arrays used directly can't be **threadsafe**, **immutable** or **have transactional integrity** and because of this, there is no direct way to go **parallel**.
3. If you need to find if specific data is contained in **sorted array** you can use **binary search**, that is not much slower then **hashset.contains** what I assume uses **VMMemoryManager.getIdentityHashCode**, that is basically just old school **modulation calculus** and where **collisions can happen**.
4. Java **generics** is just **compiler magic**, but if you want to use **Java generic** with arrays, then you can't use **primitive types**.
5. In Java 6, **Collections.sort()** works like - dump data in array and ... - at that point difference is x2 times in memory.
6. **Garbage collector** really does not like arrays, and thy usually end up in **old generation**, and wont be freed any soon.
7. It's a bad idea to enter **big** data **elements** in arrays, but i can't remember why.在我看来,数组是存储数据的最佳方法之一,而不是直接存储数据。有时,我的头就像一个垃圾桶,在那里知识是畸形的。这就是我问这个问题的原因之一--来证实我所知道的。
发布于 2010-10-03 20:36:48
由于Java5,数组很少是存储数据的最佳方法--泛型集合几乎总是优越的:
first)
List<T>,而且可以使用List<? extends T>和List<? super T>,而不是T[] (T[]对应于三个变体中的第二个,而非泛型的是不变的,这简单地说意味着,例如List<String>不是List<Object> )--这可以避免运行时异常,因为编译器可以检测它们并给出错误的messagescontainscontainsList<String>[]。
发布于 2010-10-04 00:11:05
您还应该知道数组的优点,并且有几个。
基元类型的
get和set操作要快一些。现在,这些空间/性能差异通常不值得担心。(收藏的灵活性和便利性超过了它们。)然而,在一些数据密集型应用程序中,这些差异可能是显著的。
发布于 2010-10-03 20:39:48
可能最容易将它们与替代方案的优势进行比较:
与
添加和删除元素要方便得多。除了在末尾添加之外,大多数操作与数组一样慢(且快速)。
与
添加和删除元素要快得多,按索引获取元素的速度非常慢。
对
contains、add和remove操作要快得多。失去元素排序。
对
允许您通过索引以外的其他方法快速访问元素。失去元素排序。
https://stackoverflow.com/questions/3851483
复制相似问题