title: file combiner not obtaining same outputs
body: <p>I'm trying to make a program that combines 2 text files after removing their duplicates from one file ( I have a 2 questions and answers lists and want to get all questions I can from both files) but when I use the following code the questions dont stay sorted as they were before to correspond the answer according to the line.</p>
  
  <pre><code>import java.util.Scanner;
  import java.io.File;
  import java.util.List;
  import java.util.LinkedList;
  import java.nio.file.Files.*;
  import java.nio.file.Paths;
  import java.nio.file.*;
  import java.util.Set;
  import java.util.HashSet;
  import java.nio.charset.Charset;
  
  class Main{
  
      public static List fileToList(String path){
  
          Scanner scanner = openFile(path);
          List&lt;String&gt; list = loadFile(scanner);
          closeFile(scanner);
  
          return list;
      }
  
      public static Scanner openFile(String path){ 
  
          Scanner scanner = null;
  
          try{    
              scanner = new Scanner(new File(path),"ISO-8859-1"); 
  
          }catch(Exception e){ e.printStackTrace(); }
  
          return scanner;
      }
  
      public static List loadFile(Scanner scanner){
  
          List&lt;String&gt; list = new LinkedList&lt;String&gt;();
  
          while(scanner.hasNextLine()){
              list.add(scanner.nextLine());
          }
  
          return list;
      }
  
      public static void closeFile(Scanner scanner){
          scanner.close();
      }
  
      public static Set fileCombiner(List&lt;String&gt; list1 , List&lt;String&gt; list2){
  
          for(int i = 0; i &lt; list1.size(); i++){
              for(int c = 0; c &lt; list2.size(); c++){
  
                  if(list1.get(i).equals(list2.get(c))){
  
                      if(list1.size() &gt; list2.size())
                          list1.remove(i);
                      else
                          list2.remove(c);
                  }
  
              }
          }
  
          //COMBINING TRIMMED FILES
  
          Set&lt;String&gt; set1 = null;
  
          if(list1.size() &gt; list2.size()){
              list1.addAll(list2);
              set1 = new HashSet&lt;String&gt;(list1);
          }
          else{
              list2.addAll(list1);
              set1 = new HashSet&lt;String&gt;(list2);
          }
  
  
          return set1;
      }
  
      public static void main(String args[]){
  
          Scanner input = new Scanner(System.in);
  
          System.out.print("Enter name of file 1: ");
          String name1 = input.next();
  
          System.out.print("Enter name of file 2: ");
          String name2 = input.next();
  
          String path1 = name1 + ".txt";
          String path2 = name2 + ".txt";
  
          List&lt;String&gt; list1 = fileToList(path1);
          List&lt;String&gt; list2 = fileToList(path2);
  
          Set set1 = fileCombiner(list1,list2);
  
          Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
  
          try{
              Files.write(Paths.get("GENERATED.txt"),set1,ISO_8859_1);
          }catch(Exception e){}
  
      }
  }
  </code></pre>