Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Agree.
Could be interesting to run some perfomance tests.
Besides smth like String.splitAsStream might be handy.
You mean there's a problem with static var? Inline value is just a magic constant without name and for me it is harder to reason about code locally.
I should use there private static. I could use instance fields if the kata was instance based, but that is not the case.
I wonder if CPU and time overhead of pattern is worth few kilobytes of memory.
String#split does not compile Pattern at all, if it detects regex contains only non-regex characters and fus should be slightly softer on CPU (but performace test are needed).
I think Pattern#splitAsStream could be used as readability argument, but in terms of overhead, I would not consider as performance optimization.
If you use String.split you create whole array in memory.
Consider using Pattern.splitAsStream to process one word at a time.
Nice. Very readable.
StringBuffer is way slower than StringBuilder, because it is synchronized. And if nowadays you see StringBuffer anywhere in single threaded code it is archaic (or poorly written) code.
BTW code from kata with +="" whould compile to StringBuilder concentrations, very inefficient ones however.
good job!
static var defined.
string.toCharArray() underneath makes a copy of the String character array (defensive programming)
If we prepare array by making new char[string.lenth()] and then iterate trought string using chatAt(i) we could avoid one array copy
Also in Java 9 there is one big optimization in terms of String concatination, that is using
invokedynamic
bytecode code, but still it is not even close to rawStringBuilder
implementation as seen in discussion on SO:https://stackoverflow.com/questions/49458564/string-concatenation-in-a-for-loop-java-9/49466784
(
javap -c
bytecode text included)Thus: string concatination is optimized in trivial cases, but in loops they are still to be optimized by hand.
string + string in a loop = multiple stringbuilders => bad
1 stringbuider (appending in a loop) => good
source? since what version?
I have been told that String use StringBuilder in higher version, so it isn't necessary anymore.
L.O.L.
But on the other hand: it is good practive to make your code universal and you have char[] array already created. It just needs to be extracted to a variable and iterated with = instead of +=.
Definitely true, but in case of few number of iterations, like in the cata above, you won't notice a difference in time
Loading more items...