我经常使用ArrayList而不是'正常' array[].
当我使用时ArrayList,我觉得好像在欺骗(或者懒惰),什么时候可以使用ArrayList一个阵列?
如何使用光标数据创建列表数组(滚动时列表显示第一个字母)?
我不确定这是否是同步我的正确方法ArrayList.
我有一个ArrayList in_queue从registerInQueue函数传入的.
ArrayList<Record> in_queue = null;
public void registerInQueue(ArrayList in_queue)
{
this.in_queue = in_queue;
}
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试同步它.这是否in_queue正确同步我的对象?
List<Record> in_queue_list = Collections.synchronizedList(in_queue);
synchronized (in_queue_list) {
while (in_queue_list.size() > 0) {
in_queue_list.remove(0);
}
}
Run Code Online (Sandbox Code Playgroud) 我目前相信:
HashMapArrayList我一般都对吗?是否存在不正确的情况?
我有这样的地图,
Map<Integer,ArrayList<Object>> myMap = new LinkedHashMap<Integer,ArrayList<Object>>();
Run Code Online (Sandbox Code Playgroud)
现在我必须迭代这个Map,然后迭代地图中的ArrayList.我怎么能用JSTL做到这一点?
我想填写ArrayList这些字符+, - ,*,^等.如何在不添加每个字符的情况下执行此操作arrayList.add()?
我看到了ArrayList的java doc,发现ArrayList的初始容量是10.
/**
* Constructs an empty list with an initial capacity of ten.
*/
public ArrayList() {
this(10);
}
Run Code Online (Sandbox Code Playgroud)
我认为如果它是2的任何力量,但为什么10?
我还检查了HashMap的初始容量,它是16,这是有道理的.
/**
* The default initial capacity - MUST be a power of two.
*/
static final int DEFAULT_INITIAL_CAPACITY = 16;
/**
* Constructs an empty <tt>HashMap</tt> with the default initial capacity
* (16) and the default load factor (0.75).
*/
public HashMap() {
this.loadFactor = DEFAULT_LOAD_FACTOR;
threshold = (int)(DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR);
table = new Entry[DEFAULT_INITIAL_CAPACITY];
init();
}
Run Code Online (Sandbox Code Playgroud)
10号后面有没有明确的原因?
美好的一天,这让我感到困惑(大脑冻结!),似乎缺少一些东西.有一个我用HashMap填充的ArrayList.现在我把我的HashMap和arraylist放进去.
Map.put(DATE, value1);
Map.put(VALUE, value2);
arraylist.put(Map);
Run Code Online (Sandbox Code Playgroud)
由于我正在解析JSON,因此arraylist的大小会增加.现在我的问题是如何从arraylist中的两个映射键获取值?我试过这个
if(!list.isEmpty()){ // list is an ArrayList
for(int k = 0; k < list.size(); k++){
map = (HashMap)list.get(k);
}
}
Log.d(TAG, "map size is" + map.size());
String [] keys = new String[map.size()];
String [] date_value = new String[map.size()];
String [] value_values = new String[map.size()];
int i = 0;
Set entries = map.entrySet();
Iterator iterator = entries.iterator();
while(iterator.hasNext()){
Map.Entry mapping = (Map.Entry)iterator.next();
keys[i] = mapping.getKey().toString();
date_value[i] = map.get(keys[i]);
if(keys[i].equals(DATE)){
date_value[i] = map.get(keys[i]);
} else if(keys[i].equals(VALUE)){ …Run Code Online (Sandbox Code Playgroud) 我使用ArrayList并尝试将其一部分复制到另一个ArrayList,因此我使用:
sibling.keys = (ArrayList<Integer>) keys.subList(mid, this.num);
Run Code Online (Sandbox Code Playgroud)
其中"sibling.keys"是新的ArrayList,"keys或this.keys"是旧的ArrayList.我使用了铸造,因为eclipse告诉我这样做但是它抛出了ClassCastException:
java.util.ArrayList $ SubList无法强制转换为java.util.ArrayList
有什么建议?
我有两个字符串对象的arraylists.
List<String> sourceList = new ArrayList<String>();
List<String> destinationList = new ArrayList<String>();
Run Code Online (Sandbox Code Playgroud)
我有一些逻辑,我需要处理源列表,并最终得到目标列表.目标列表将添加一些其他元素添加到源列表或从源列表中删除.
我的预期输出是2个字符串ArrayList,其中第一个列表应该从源中删除所有字符串,第二个列表应该具有新添加到源的所有字符串.
任何更简单的方法来实现这一目标?