arraylist

java.util.ConcurrentModificationException on ArrayList

ぐ巨炮叔叔 提交于 2019-12-18 06:56:37
问题 I have a Server class and a Timer inside it which is supposed to clear dead clients (clients who crashed). I followed the example below by locking the collection when the Timer iterates over the users but I still get this exception (after I crash a connected client). http://www.javaperformancetuning.com/articles/fastfail2.shtml List<User> users; List<User> connectedUsers; ConcurrentMap<User, IClient> clients; ... users = Collections.synchronizedList(new ArrayList<User>()); connectedUsers =

Java: Interleaving multiple arrays into a single array

喜夏-厌秋 提交于 2019-12-18 05:57:07
问题 I found similar question about interleaving two arraylists into one, but its in PHP. I was asked this question in interview as well but could'nt solve it, came back to SO to look if it was addressed already, but i could only find this paper So any pointers to pseudo code or method definition ? Big(O) restrictions : O(n) - time cost and O(1) - space cost Example: a[]= a1, a2, ..., an b[]= b1, b2, ..., bn Rearrange the arraylist to a1, b1, a2, b2, ..., an, bn Editv1.0 : Arraylists a[] and b[]

Why primitive datatypes are not allowed in java.util.ArrayList? [duplicate]

我的未来我决定 提交于 2019-12-18 05:49:26
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Storing primitive values in a Java collection? ArrayList accepts only reference types as its element, not primitive datatypes. When trying to do so it produces a compile time error. What is the concept behind this? It seems like a limitation, is it not? 回答1: All collection classes of java store memory location of the objects they collect. The primitive values do not fit in to the same definition. To circumvent

Passing ArrayList with objects to new Activity?

大憨熊 提交于 2019-12-18 05:48:13
问题 I'm trying to pass an ArrayList from my first Activity to the next one. Basically, the first activity parses an XML file and creates an ArrayList with objects inside. What I want to do is send that ArrayList to my second activity and show some of the object data in a ListView. I thought of doing this with an intent, but it looks like only primitive datatypes are usually passed through intents. Is this right? If so, what would be a better solution to pass the data? Certainly Android must

Why is there an ArrayList declaration within java.util.Arrays

半世苍凉 提交于 2019-12-18 05:28:10
问题 In JDK 1.7, there is an ArrayList declaration which is used by asList . Why did they make a new private static class and not use java.util.ArrayList : @SafeVarargs public static <T> List<T> asList(T... a) { return new ArrayList<>(a); } /** * @serial include */ private static class ArrayList<E> extends AbstractList<E> implements RandomAccess, java.io.Serializable { private static final long serialVersionUID = -2764017481108945198L; private final E[] a; ArrayList(E[] array) { if (array==null)

Problem serializing and deserializing ArrayList

十年热恋 提交于 2019-12-18 05:18:13
问题 Anytime I try to serialize a file I get the error: FileNotFound. Not sure why. Here is my FileHelper code: package org.stocktwits.helper; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.ArrayList; import org

android: problem with Serializable object put into intent

自闭症网瘾萝莉.ら 提交于 2019-12-18 05:06:06
问题 Hi i have problem with a class i want to pass in an intent by putting it into the putExtras() Its serializable and the code looks like this: public abstract class ObjectA extends ArrayList<ObjectA> implements java.io.Serializable{...} public class ObjectB extends ObjectA {...} ... Bundle extras = new Bundle(); extras.putSerializable("blabla", ObjectB); intent.putExtras(extras); ... Object y = getIntent().getExtras().get("blabla"); the problem is, that y now is an ArrayList and no longer an

android: problem with Serializable object put into intent

陌路散爱 提交于 2019-12-18 05:06:01
问题 Hi i have problem with a class i want to pass in an intent by putting it into the putExtras() Its serializable and the code looks like this: public abstract class ObjectA extends ArrayList<ObjectA> implements java.io.Serializable{...} public class ObjectB extends ObjectA {...} ... Bundle extras = new Bundle(); extras.putSerializable("blabla", ObjectB); intent.putExtras(extras); ... Object y = getIntent().getExtras().get("blabla"); the problem is, that y now is an ArrayList and no longer an

Firebase Firestore get data from collection

早过忘川 提交于 2019-12-18 04:55:10
问题 I want to get data from my Firebase Firestore database. I have a collection called user and every user has collection of some objects of the same type (My Java custom object). I want to fill my ArrayList with these objects when my Activity is created. private static ArrayList<Type> mArrayList = new ArrayList<>();; In onCreate(): getListItems(); Log.d(TAG, "onCreate: LIST IN ONCREATE = " + mArrayList); *// it logs empty list here Method called to get items to list: private void getListItems()

Retrieving elemnts from an ArrayList by specifying the indexes

☆樱花仙子☆ 提交于 2019-12-18 04:49:24
问题 Is there a method in Java to get the list of objects from an Arraylist to another ArrayList, by just specifying the start and end index? 回答1: Yes you can use the subList method: List<...> list2 = list1.subList(startIndex, endIndex); This returns a view on that part of the original list, it does not copy the data. If you want a copy: List<...> list2 = new ArrayList<...> (list1.subList(startIndex, endIndex)); 回答2: /create an ArrayList object ArrayList arrayList = new ArrayList(); //Add elements