arraylist

HashSet vs. ArrayList

[亡魂溺海] 提交于 2019-12-18 04:44:17
问题 So I have a custom class Class that will have a set of another custom class Students. So it will look something like this: public class Class { private Set<Student> students; // other methods } Now I will be adding and removing many students to the set students and i will also be changing many of the private fields of a student already in the set of students. QUESTION: What data structure should I use to best implement this? Since I will be changing the property of the Student objects in set

Convert List of List into list in java

最后都变了- 提交于 2019-12-18 04:41:08
问题 List<List<String>> superlist = new ArrayList<List<String>>(); List<String> list1 = new ArrayList<String>(); list1.add("a1"); list1.add("a2"); List<String> list2 = new ArrayList<String>(); list2.add("b1"); list2.add("b2"); List<String> list3= new ArrayList<String>(); list3.add("c1"); list3.add("c2"); superlist.add(list1); superlist.add(list2); superlist.add(list3); List<String> result= new ArrayList<>(); Now I want to create a new list which contains all the values in superList . Here result

Convert List of List into list in java

扶醉桌前 提交于 2019-12-18 04:41:08
问题 List<List<String>> superlist = new ArrayList<List<String>>(); List<String> list1 = new ArrayList<String>(); list1.add("a1"); list1.add("a2"); List<String> list2 = new ArrayList<String>(); list2.add("b1"); list2.add("b2"); List<String> list3= new ArrayList<String>(); list3.add("c1"); list3.add("c2"); superlist.add(list1); superlist.add(list2); superlist.add(list3); List<String> result= new ArrayList<>(); Now I want to create a new list which contains all the values in superList . Here result

i need to find a integer data in arraylist?

会有一股神秘感。 提交于 2019-12-18 04:35:18
问题 I have an Arraylist . If user enter the same number secondly I want to show to user. For this I need to find Arraylist have it or not. I hope I made myself clear. 回答1: If you are checking to see if some value is stored in an ArrayList you can use the contains() method, this will return true if the object is in the list, false otherwise. ArrayList<Integer> intList = new ArrayList<>(); intList.add(5); intList.add(7); intList.add(3); intList.add(-2); intList.contains(-1); //returns false intList

filtering an ArrayList using an object's field

会有一股神秘感。 提交于 2019-12-18 04:34:12
问题 I have an ArrayList which is filled by Objects. My object class called Article which has two fields ; public class Article { private int codeArt; private String desArt; public Article(int aInt, String string) { this.desArt = string; this.codeArt = aInt; } public int getCodeArt() {return codeArt; } public void setCodeArt(int codeArt) {this.codeArt = codeArt;} public String getDesArt() {return desArt;} public void setDesArt(String desArt) { this.desArt = desArt;} } I want to filter my List

Class not found when Unmarshalling Android Intent Parcelable

天大地大妈咪最大 提交于 2019-12-18 04:32:07
问题 I have a ArrayList that I am passing between activities . In this ArrayList are objects made from a class that has four variables in it. One of those variables is another ArrayList<object> that is from another class . I have implemented Parcelable on both and am pretty sure I have completed the parcelable methods properly. Here are the errors: Errors: 03-18 02:37:27.063: D/dalvikvm(3249): GC_FOR_ALLOC freed 82K, 6% free 3020K/3180K, paused 1ms, total 3ms 03-18 02:37:27.093: I/dalvikvm-heap

How to compare two ArrayList<List<String>>

蹲街弑〆低调 提交于 2019-12-18 04:23:41
问题 I want to compare these two ArrayList : public static ArrayList<List<String>> arrayList1 = new ArrayList<List<String>>(); public static ArrayList<List<String>> arrayList2 = new ArrayList<List<String>>(); If they have the same elements it will return true, otherwise false. 回答1: You can try using Apache commons CollectionUtils.retainAll method : Returns a collection containing all the elements in collection1 that are also in collection2. ArrayList commonList = CollectionUtils.retainAll

Avoiding overwriting objects in ArrayList

别等时光非礼了梦想. 提交于 2019-12-18 04:23:09
问题 Stackers. I've been searching the site for my question, but didn't find what I was looking for. I'm stuck with this code: public class Users{ ArrayList<ValidateUser> personer = new ArrayList<ValidateUser>(); ValidateUser newUser = new ValidateUser(); newUser.setUser("administrator"); newUser.setPass("asdf123"); newUser.setBalance(0.8); newUser.setType("admin"); personer.add(newUser); Got a nice array-list going on, but if i add more "newUsers" to the ArrayList, they seem to overwrite each

Generating All Permutations of Character Combinations when # of arrays and length of each array are unknown

ぐ巨炮叔叔 提交于 2019-12-18 04:15:01
问题 I'm not sure how to ask my question in a succinct way, so I'll start with examples and expand from there. I am working with VBA, but I think this problem is non language specific and would only require a bright mind that can provide a pseudo code framework. Thanks in advance for the help! Example: I have 3 Character Arrays Like So: Arr_1 = [X,Y,Z] Arr_2 = [A,B] Arr_3 = [1,2,3,4] I would like to generate ALL possible permutations of the character arrays like so: XA1 XA2 XA3 XA4 XB1 XB2 XB3 XB4

while-else-loop

大兔子大兔子 提交于 2019-12-18 04:09:21
问题 Of course this is an impossible statement in java (to-date), however ideally I would like to implement it as it is at the heart of many iterations. For example the first multiple times it is called I'm doing it 650,000+ times when it is creating the ArrayList . Unfortunately the reality is that my actual code does not have the set inside the else loop; thus it will pass over both the add and then the set commands and wasting time. After that I have it also in another loop where it is only