Java. How to OpenService program work?

Want to start by saying that I am a beginner, my code is far from perfect and most likely it needs to be edited or redone.
Now, the problem is this: the Program must print all permutations of multisets without repetitions, a MultiSet to be entered from the keyboard.

The code itself is given below. I must say that it works very properly.
The problem is this: the program works only to enter 10 numbers, then doesn't. As 10! - it is 4 million combinations. ArrayList apparently filled to the end, the result finical OutOfMemoryError Exeption. What to do ? How to be? Any help would be appreciated.

Forgot to say about the theory itself. MultiSet - a set of numbers.
A = {1^2 ,2^3 ,3^3 ,4^2 ,5^1};
Here degree is the number of repetitions. Ie this multin. it was possible to introduce in the form:
A = {1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5};
Based on these numbers, you need to build a permutation without repetition.

My program:
1.I get so many in ArrayList
2.Recursively make permutation
3.Adeeva extra with the help of Hasset
4.Write to the file. Because in the console all the permutations do not fit.

import java.io.*;
import java.util.*;

import static java.util.Collections.swap;


public class Main {

 private static ArrayList <string> rec_filter = new ArrayList<>();
 private static String fileName = "new_file.txt";
 private static ArrayList<string> in = new ArrayList<string>();

 public static ArrayList<integer> return_Arrlist() throws IOException {
 BufferedReader bufferedReader = new BufferedReader(new an InputStreamReader(System.in));
 ArrayList<integer> list = new ArrayList<integer>();

 while (true) {
 String s = bufferedReader.readLine();
 if (s.equals("")) break;
 int num = Integer.parseInt(s);
 System.out.print(num + "^");
 Tmp_step String = bufferedReader.readLine();
 int stepin = Integer.parseInt(tmp_step);
 in.add(num + "^" + tmp_step);
 while (stepin > 0) {
list.add(num);
stepin--;
}
}

 System.out.println("you Entered Multimeida:" +"\n A = " +in);
 return list;
}

 public static void permute(ArrayList<integer> list, int start) throws IOException {
 for (int j = start; j <= list.size() - 1; j++) {
 swap(list, start, j);
//System.out.println(list);
 permute(list, start + 1);
 swap(list, start, j);
}
rec_filter.add(list.toString());
}

 public static void main(String[] args) throws IOException {
 permute(return_Arrlist(), 0);
 int count = 0;
 List <string> list = rec_filter;
 Set <string> set = new HashSet<>(list);
rec_filter.removeAll(rec_filter);
list.removeAll(list);
in.removeAll(in);
 long startTime = System.currentTimeMillis();

 File File = new File(fileName);
 try {
 BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));
 for (Iterator iter = set.iterator(); iter.hasNext();) {
count++;
 //System.out.println(count+") "+ iter.next());
 writer.write(count+") "+ iter.next()+"\n");
}
writer.close();
}
 catch (Exception ex){
ex.printStackTrace();
}

 String s = "----------------------------------------\n";
System.out.printf("%s",s);
 System.out.println("Slogo Mogilevich kombinaci:" +count);
System.out.printf("%s",s);
 long timeSpent = System.currentTimeMillis() - startTime;
 System.out.println("the program of vigonovese" + (timeSpent*10e-6) + "seconds");
}
}</string></string></integer></integer></integer></integer></string></string></string>
July 2nd 19 at 13:57
3 answers
July 2nd 19 at 13:59
Firstly - you don't need to store all permutations in memory of the computer. They can throw the disc immediately after generation. But not the fact.
Secondly, perhaps you need the algorithm Naraina.
Thirdly, not all need the ArrayList. In many situations you can do a fixed-size array. For example, to store the current permutation.
Fourth - if you have so much generated permutations - there's a chance that they are in HashSet will not fit. I think you should think about sorting and filtering in the external memory.
Fifth - are there any restrictions on memory usage and total time of work?
Sixth - if you use the algorithm Naraina - you can save the memory for storing the result in some cases. Hint - look at the MultiSet of species {1^10, 2^1} 11 non-unique and two unique permutations and assume how many of these permutations will be stored in the HashSet.

PS: And the output language you Ukrainian or Belarusian? The word "multimedia" worth remembering. In addition, you do not need to use printf where you can write println(s). But where printf would be useful - are you using println. Compare with your code.
String s = "----------------------------------------";
System.out.println(s);
System.out.printf("Slogo Mogilevich kombinaci: %d ",count);
System.out.println(s);
long timeSpent = System.currentTimeMillis() - startTime;
System.out.printf("the program of vigonovese %f seconds", (timeSpent*10e-6));
July 2nd 19 at 14:01
the result finical OutOfMemoryError Exeption. What to do ? How to be?

Increase the amount of memory in the computer.
July 2nd 19 at 14:03
as far as I understand you have the most memory consumes a list<string></string> and set<string></string> due to the fact that you have the memory contains millions of rows.
I think that it is better not to do it list<string></string>from the sets and do hashcode() resulting from one set string and then this poluvsie of the hashcode() integer add to set<integer></integer>and if added then save the string to disk - such a decision would have to eat several times less memory

Find more questions by tags Java