I have an input which contains one symbol on each line and have used scanner to read into an arralist (maybe). I would like to have 1000 subsets of data randomly from this arraylist (size=3) and save it into a file line by line(each line is a subset).
So the input is like :
AAA BBB CCC DDD EEE FFF Expected output would be:
AAA EEE FFF CCC FFF BBB DDD BBB AAA Here is what I have so far. I'm kind of stucking on how to indicate 1000 time of shuffling and how to define size=3. I expect if I can shuffle 1000 times and pick up first 3 on each. It is my strategy.
public class sampling { public static void main(String[] args) throws FileNotFoundException{ Scanner scan1 = new Scanner(new File("Symbol.txt")); ArrayList<String> Wholelist = new ArrayList<>(); while (scan1.hasNextLine()){ String line = scan1.nextLine(); Wholelist.add(line); } try{ FileWriter stream = new FileWriter(args[2]); BufferedWriter out = new BufferedWriter(stream); for (int i=0,n=Wholelist.size();i<n; i++){ Collections.shuffle(Wholelist); Wholelist.get(3); } } catch (IOException e) { System.err.println("Error: "+ e.getMessage()); } } } Please try to modify it based on my code because I'm a beginner of Java. Thank you so much if anyone can help.