Initial size for the ArrayList

You can set the initial size for an ArrayList by doing ArrayList<Integer> arr=new ArrayList<Integer>(10); However, you can’t do arr.add(5, 10); because it causes an out of bounds exception. What is the use of setting an initial size if you can’t access the space you allocated? The add function is defined as add(int index, Object element) … Read more

RecyclerView: Inconsistency detected. Invalid item position

Our QA has detected a bug: when rotating the Android device (Droid Turbo), the following RecyclerView-related crash happened: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 2(offset:2).state:3 To me, it looks like an internal error inside RecyclerView, as I can’t think of any way of this being caused directly by our code… Has anyone encountered this problem? … Read more

Java string split with “.” (dot) [duplicate]

This question already has answers here: Split string with dot as delimiter (13 answers) Closed 9 years ago. Why does the second line of this code throw ArrayIndexOutOfBoundsException? String filename = “D:/some folder/001.docx”; String extensionRemoved = filename.split(“.”)[0]; While this works: String driveLetter = filename.split(“https://stackoverflow.com/”)[0]; I use Java 7. 4 Answers 4