Timeline for Calculate all possible combinations of given characters
Current License: CC BY-SA 3.0
8 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Apr 17, 2015 at 22:28 | comment | added | TheCoffeeCup | It might be called multiple times, and sometimes the small time difference is vital. And one object is better that 10. | |
Apr 17, 2015 at 3:41 | comment | added | user949300 |
The StringBuilder will eventually be accessed viatoString() , creating an Object. Nowhere does OP suggest that this will be called thousands of times, let alone thousands of millions.
|
|
Apr 16, 2015 at 22:58 | comment | added | TheCoffeeCup |
Good first point, but for the second point, curr += alphabet[i] can easily be solved using a StringBuilder , as the accepted answer suggested. Also, 10 extra objects is a lot if you run this thousands or millions of times. For example, if the most optimized (i.e. no extra objects) method runs in, lets say, 10 milliseconds, and the other one takes 11 milliseconds, that's a 1,000 to 1,000,000 millisecond difference.
|
|
Apr 16, 2015 at 16:51 | comment | added | user949300 |
@Manny Meng First, it only creates one new String, newCurr. Second, because Strings are immutable, you can't avoid this. In the OP's code curr += alphabet[i] also creates a new String. So your comment and downvote are incorrect. Finally even if one extra object were created, in this example nobody cares, it's only like 10 extra objects.
|
|
Sep 28, 2014 at 17:47 | comment | added | TheCoffeeCup |
That would cause it to create TWO new strings each time it runs: newCurr and curr + alphabet[i]
|
|
Feb 12, 2014 at 22:39 | history | migrated | from stackoverflow.com (revisions) | ||
Feb 12, 2014 at 7:26 | comment | added | Phazor | Thanks, this was also very helpful. I've never thought about it like that. Cheers. | |
Feb 12, 2014 at 6:51 | history | answered | user949300 | CC BY-SA 3.0 |