arraylist

How can I check if an ArrayList contains any element of another ArrayList? [duplicate]

跟風遠走 提交于 2020-05-14 14:43:06
问题 This question already has answers here : Check if one list contains element from the other (11 answers) Closed 5 years ago . Is there any way to determine whether an ArrayList contains any element of a different ArrayList? Like this: list1.contains(any element of list2) Is looping through all the elements of list2 and checking the elements one by one the only way? 回答1: Although not highly efficient, this is terse and employs the API: if (!new HashSet<T>(list1).retainAll(list2).isEmpty()) //

Convert ArrayList with Gson to String

点点圈 提交于 2020-05-12 15:32:19
问题 I have an ArrayList which contains ArrayLists , each ArrayList in the Root list contains one ArrayList of Integers and one of Strings . I am converting it with Gson to a String to save it with SharedPreferences. But when I am reconverting it, Gson gives me 2.131558489E9 instead of the original int 2131558489 . How can I fix this Problem? Best Regards. Here is how I convert the ArrayList: levelPattern is the ArrayList String levelPatternGson = new Gson().toJson(levelPattern); And this is how I

Convert ArrayList with Gson to String

帅比萌擦擦* 提交于 2020-05-12 15:32:11
问题 I have an ArrayList which contains ArrayLists , each ArrayList in the Root list contains one ArrayList of Integers and one of Strings . I am converting it with Gson to a String to save it with SharedPreferences. But when I am reconverting it, Gson gives me 2.131558489E9 instead of the original int 2131558489 . How can I fix this Problem? Best Regards. Here is how I convert the ArrayList: levelPattern is the ArrayList String levelPatternGson = new Gson().toJson(levelPattern); And this is how I

Convert ArrayList with Gson to String

你离开我真会死。 提交于 2020-05-12 15:26:11
问题 I have an ArrayList which contains ArrayLists , each ArrayList in the Root list contains one ArrayList of Integers and one of Strings . I am converting it with Gson to a String to save it with SharedPreferences. But when I am reconverting it, Gson gives me 2.131558489E9 instead of the original int 2131558489 . How can I fix this Problem? Best Regards. Here is how I convert the ArrayList: levelPattern is the ArrayList String levelPatternGson = new Gson().toJson(levelPattern); And this is how I

Modifying each item of a List in java

风流意气都作罢 提交于 2020-05-09 20:47:47
问题 I'm just starting to work with lists in java. I'm wondering what the recommended method to modify each element of a list would be? I've been able to get it done with both the following methods, but they both seem fairly unelegant. Is there any better way to get this done in java? And is any of the below methods recommended over the other, or are both on the same level? //Modifying with foreach for (String each : list) { list.set(list.indexOf(each), each+ " blah"); } //Modifying with for for

Modifying each item of a List in java

筅森魡賤 提交于 2020-05-09 20:45:10
问题 I'm just starting to work with lists in java. I'm wondering what the recommended method to modify each element of a list would be? I've been able to get it done with both the following methods, but they both seem fairly unelegant. Is there any better way to get this done in java? And is any of the below methods recommended over the other, or are both on the same level? //Modifying with foreach for (String each : list) { list.set(list.indexOf(each), each+ " blah"); } //Modifying with for for

Dynamically adding elements to ArrayList in Groovy

梦想的初衷 提交于 2020-05-09 20:00:29
问题 I am new to Groovy and, despite reading many articles and questions about this, I am still not clear of what is going on. From what I understood so far, when you create a new array in Groovy, the underlying type is a Java ArrayList. This means that it should be resizable, you should be able to initialize it as empty and then dynamically add elements through the add method, like so: MyType[] list = [] list.add(new MyType(...)) This compiles, however it fails at runtime: No signature of method:

Android TimeZone.getAvailableIDs() producing strange strings

限于喜欢 提交于 2020-04-30 07:52:57
问题 I have an Android application which uses TimeZone.getAvailableIDs() to pull all available timezone ID strings. These IDs are saved to an ArrayList , as per the following: ArrayList<String> clocks = new ArrayList<>(); String[] ids = TimeZone.getAvailableIDs(); Collections.addAll(clocks, ids); This ArrayList is used later on to populate a ListView using my custom BaseAdapter. There are a few entries that aren't particularly informative and I don't want them in the list, such as: Etc/GMT+10

Android TimeZone.getAvailableIDs() producing strange strings

落爺英雄遲暮 提交于 2020-04-30 07:52:37
问题 I have an Android application which uses TimeZone.getAvailableIDs() to pull all available timezone ID strings. These IDs are saved to an ArrayList , as per the following: ArrayList<String> clocks = new ArrayList<>(); String[] ids = TimeZone.getAvailableIDs(); Collections.addAll(clocks, ids); This ArrayList is used later on to populate a ListView using my custom BaseAdapter. There are a few entries that aren't particularly informative and I don't want them in the list, such as: Etc/GMT+10

Android TimeZone.getAvailableIDs() producing strange strings

空扰寡人 提交于 2020-04-30 07:52:08
问题 I have an Android application which uses TimeZone.getAvailableIDs() to pull all available timezone ID strings. These IDs are saved to an ArrayList , as per the following: ArrayList<String> clocks = new ArrayList<>(); String[] ids = TimeZone.getAvailableIDs(); Collections.addAll(clocks, ids); This ArrayList is used later on to populate a ListView using my custom BaseAdapter. There are a few entries that aren't particularly informative and I don't want them in the list, such as: Etc/GMT+10