0

How to generate large amounts of Strings fast in Java

So as i said i wanna generate a huge amount of Strings very fast. And with huge amount i mean like 8^10 or something like that. And please if you know how to do it, load it in a collection like arrayList or so because i need excess to every String in the Collection. I tried like multithreading but its still takes soooooooo long to generate every single possibility. If you need to know what im trying to do: I want to generate every single possible combination of a password that is, at first, 8 digits long.

12th Oct 2017, 8:13 PM
Niklas
Niklas - avatar
6 Réponses
+ 3
If you are using any concatenation, try using a StringBuilder. Use the append() method to add to the StringBuilder just like you would with concatenation. Then, you can use the toString() method to get the String value (No imports required). Also, if you know (roughly) how many Strings you will need, initializing the starting capacity of the Arraylist may help. Ex/ ArrayList<String> passes = new ArrayList<>(10000); Perhaps the algorithm can also be improved? Are duplicates created? May I ask why you want to store every possible combination?
12th Oct 2017, 9:04 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
or generate the list once (like word dictionary) and call it from your program
12th Oct 2017, 9:05 PM
Martin R
Martin R - avatar
+ 1
7E14 possible choices and the only reason I can think of to do so is illegal. You can't get them in memory. You need 560TB of storage for it.
12th Oct 2017, 10:10 PM
John Wells
John Wells - avatar
0
@John Wells i dont want anything illegal i just want to know how to generate a very large amount of String and is it really so memory intense that ill need 560TB of storage i cant imagine that an arrayList even with this big number of Strings in it.
13th Oct 2017, 4:19 AM
Niklas
Niklas - avatar
0
@Martin R thats what i want to do but it would still take so long for generating every String. i already have a code that could do the job but it is sooooo slow and i just want to improve it.
13th Oct 2017, 4:20 AM
Niklas
Niklas - avatar
0
@Rrestoring faith thanks for the answer and i really like the idea but i dont see just yet why i should string builder instead of just changing the string value and adding it to an arrayList. And with the capacity of the arrayList i know about how many i need so ill try it out as soon as i can. To answer your questions: 1. Im sorry but i cant understand what the first question means im not that great in English. 2. i dont need duplicates. 3. When im ready ill let ya see ;P
13th Oct 2017, 4:28 AM
Niklas
Niklas - avatar