[英]Android maximum arraylist size
I am reading from SQLite
in android some name of Files
, I have like 3000 names that are added to an ArrayList
but I discovered that I can't have more than 1000. Is 1000 maximum size of an ArrayList<String>
?我正在从 android 中的
SQLite
读取一些Files
名称,我有 3000 个名称添加到ArrayList
但我发现我不能超过 1000 个。 ArrayList<String>
最大大小是 1000 吗? Searching over the internet I found that depends.在互联网上搜索我发现这取决于。
I found some math operations here ( http://www.coderanch.com/t/524745/java/java/Maximum-capacity-arrayList-String-objects ) with 1000, and I found that the maximum capacity of an ArrayList<String>
is given by Java Virtual Machine Memory.我在这里找到了一些数学运算( http://www.coderanch.com/t/524745/java/java/Maximum-capacity-arrayList-String-objects ),有 1000 个,我发现
ArrayList<String>
的最大容量ArrayList<String>
由 Java 虚拟机内存提供。
Is there a way how to increase this ?有没有办法增加这个?
I have created an arrayList
, its unlimited.我创建了一个
arrayList
,它是无限的。 you can also manipulate it to your desire, its has all the basic features of an arraylist
.您也可以根据需要对其进行操作,它具有
arraylist
所有基本功能。
here is the code.这是代码。
public class BetterArray<E> {
private E[] array;
private final int DEFAULT_ARRAY_SIZE = 10;
private int size;
private void copyArray(E[] copyFrom, E[] copyTo) {
for (int i = 0; i <= copyFrom.length-1; i++) {
copyTo[i] = copyFrom[i];
}
}
private void createAnotherArray(){
int newSize = 2 * array.length;
E[] newArray = (E[])(new Object[newSize]);
copyArray(array, newArray);
array = newArray;
}
public BetterArray() {
array = (E[]) (new Object[DEFAULT_ARRAY_SIZE]);
this.size = 0;
}
public E get(int index){
if(index < 0 || index > size){
throw new RuntimeException("index not valid");
}
else{
return array[index];
}
}
public boolean isEmpty() {
if (size == 0)
return true;
else
return false;
}
public void insert(int position, E element) {
if(isFull())
createAnotherArray();
E previous_temp = get(position);
array[position]= element;
for(int k = position+1; k<= size; k++){
E current_temp = get(k);
array[k] = previous_temp;
previous_temp = current_temp;
}
size++;
}
public void append(E element) {
insert(size, element);
}
public void remove(int index){
for (int i = index; i <= size-1; i++){
array[i] = get(i+1);
}
size--;
}
public void shift(E element){
insert(0, element);
}
public boolean isFull() {
if (size == array.length)
return true;
return false;
}
public int size(){
return size;
}
public String toString(){
StringBuilder returnString = new StringBuilder();
for(int i= 0; i <= size-1; i++){
returnString.append(get(i).toString() + ", ");
}
return returnString.toString();
}
// public int index(E element){
// return 1;
// }
public void reverse(){
E temp_storage;
int halfSize = (size/2) ;
for (int k= 0; k<= halfSize; k++ ){
temp_storage = array[k];
array[k] = array[size-k-1];
array[size-k-1] = temp_storage;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.