ArrayOutOfBoundsException on Bean creation while using Java 8 constructs
Which version of Spring do you use? You need upgrade to Spring 4 to use Java 8 lambda expressions.
Which version of Spring do you use? You need upgrade to Spring 4 to use Java 8 lambda expressions.
It is a pity that substring is not implemented in a way that handles short strings – like in other languages e.g. Python. Ok, we cannot change that and have to consider this edge case every time we use substr, instead of if-else clauses I would go for this shorter variant: myText.substring(0, Math.min(6, myText.length()))
According to the api-doc: val list = arrayListOf<Int>() This is also mentioned here: How to initialize List in Kotlin? .
Capacity does not equal size. The size parameter that you are passing in simply allocates enough memory for the size. It does not actually define elements. It’s actually kind of a silly requirement of Collections.copy, but it is one nonetheless. The key part from the Collections.copy JavaDocs: The destination list must be at least as … Read more
Am I doing that right, as far as iterating through the Arraylist goes? No: by calling iterator twice in each iteration, you’re getting new iterators all the time. The easiest way to write this loop is using the for-each construct: for (String s : arrayList) if (s.equals(value)) // … As for java.lang.ArrayIndexOutOfBoundsException: -1 You just … Read more
Here’s a neat solution: String upToNCharacters = s.substring(0, Math.min(s.length(), n)); Opinion: while this solution is “neat”, I think it is actually less readable than a solution that uses if / else in the obvious way. If the reader hasn’t seen this trick, he/she has to think harder to understand the code. IMO, the code’s meaning … Read more
You’re confusing the size of the array list with its capacity: the size is the number of elements in the list; the capacity is how many elements the list can potentially accommodate without reallocating its internal structures. When you call new ArrayList<Integer>(10), you are setting the list’s initial capacity, not its size. In other words, … Read more
I had a (possibly) related issue – entering a new instance of an activity with a RecyclerView, but with a smaller adapter was triggering this crash for me. RecyclerView.dispatchLayout() can try to pull items from the scrap before calling mRecycler.clearOldPositions(). The consequence being is that it was pulling items from the common pool that had … Read more
Ultimately it probably doesn’t have a safe .get method because a dict is an associative collection (values are associated with names) where it is inefficient to check if a key is present (and return its value) without throwing an exception, while it is super trivial to avoid exceptions accessing list elements (as the len method … Read more
You need to escape the dot if you want to split on a literal dot: String extensionRemoved = filename.split(“\\.”)[0]; Otherwise you are splitting on the regex ., which means “any character”. Note the double backslash needed to create a single backslash in the regex. You’re getting an ArrayIndexOutOfBoundsException because your input string is just a … Read more