title: How to subtract values of two lists/arrays in Java?
body: <p>I am working on a Java project and I am having a problem. I want to have the subtract of two lists or arrays a and b in list/array c but I don't know how to do that. I want "a[i] -b[i]" should be in next list c where the value should be <code>c[i]</code> similarly for 5-2=3  any suggestion and help would be appreciated.</p>
  
  <p>Code:</p>
  
  <pre><code>public static void länge() {
      {
          BufferedReader br = null;
          try {
              br = new BufferedReader(new FileReader(new File("C:\\Users/Voodoothechild/Desktop/Pidata/Anfang.txt")));
              String line = null;
              while ((line = br.readLine()) != null) {         
                  {
                      BufferedReader bro = null;
                      try {
                          bro = new BufferedReader(new FileReader(new File("C:\\Users/Voodoothechild/Desktop/Pidata/Ende.txt")));
  
                          String lines = null;
                          while ((lines = br.readLine()) != null) {
  
                              String[] anfang = line.split("\n");
                              String[] ende = lines.split("\n");
  
                              List&lt;Integer&gt; an = new ArrayList&lt;Integer&gt;();
                              List&lt;Integer&gt; en = new ArrayList&lt;Integer&gt;();
  
                              for (int index = 0 ; index&lt;ende.length ; index++) {
  
                                  an.add(Integer.parseInt(anfang[index]));
                                  en.add(Integer.parseInt(ende[index]));
                                  Integer[] anf = new Integer[an.size()];
  
                                  int[] result = new int[anf.length]; 
  
                                  for (int i = 0; i &lt; result.length; i++) { 
                                      result[i] = anf[i] - end[i]; 
                                  } 
  
                              } 
                          }    
                      } catch (FileNotFoundException e) {
                          e.printStackTrace();
                      } catch (IOException e) {
                          e.printStackTrace();
                      } finally {
                          if (bro != null) {
                              try {
                                  bro.close();
                              } catch (IOException e) {
                                  e.printStackTrace();
                              }
                          }
                      }
                  }
              }
          } catch(FileNotFoundException e) {
              e.printStackTrace();
          } catch(IOException e) {
              e.printStackTrace();
          } finally {
              if (br != null) {
                  try {
                      br.close();
                  } catch(IOException e) {
                      e.printStackTrace();
                  }
              }
          }
      }
  }
  </code></pre>