title: read a file and assign key, values java
body: <p>so I'm trying to make a greedy/jewel heist algorithm in java. I saved the numbers and weights for the jewels to a .txt file. My program is correctly reading the .txt file and I've written a program that can successfully read them. these are the numbers from my .txt file</p>
  
  <pre><code>575 - bag limit
  125 3000 (weight, value)
  50 100
  500 6000
  25 30
  </code></pre>
  
  <p>The problem I'm running into is that I'm struggling to add weights and values to the program.  ideally the program would read the tuples and assign them keys and values. I tried to use a hashmap and a regular Map but they haven't been working. possibly because they're in the wrong place. I included both attempted maps and have them commented out like in my program. Would love some help on assigning these values so I can move on to the next step. thanks!!</p>
  
  <pre><code>    import java.io.BufferedReader;
      import java.io.File;
      import java.io.FileReader;
      import java.io.IOException;
      import java.nio.file.Files;
      import java.nio.file.Paths;
  //    import java.util.HashMap;
  //    import java.util.Map;
      public class readstringastext {
  
          public static void main(String[] args) {
              try {
                  File file = new File("test.txt");
                  FileReader fileReader = new FileReader(file);
                  BufferedReader bufferedReader = new 
                  BufferedReader(fileReader);
                  StringBuffer stringBuffer = new StringBuffer();
                  String line;
                  String weightLimit = Files.readAllLines(Paths.get("test.txt")).get(0); 
                  while ((line = bufferedReader.readLine()) != null) {
                      stringBuffer.append(line);
                      stringBuffer.append("\n");
                  }
                  fileReader.close();
      }       catch (IOException e) {
                  e.printStackTrace();
              }
      }
              HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  //
  //          for (String string : pairs) {
  //              String[] keyValue = string.split(" "); 
  //              map.put(keyValue[0], keyValue[1]);
  //              System.out.println(keyValue);
  //      };
  //final class MyEntry&lt;K, V&gt; implements Map.Entry&lt;K, V&gt; {
  //  private final K key;
  //  private V value;
  //  
  //  public MyEntry(K key, V value) {
  //      this.key = key;
  //      this.value = value;
  //  }   
  //  @Override 
  //  public K getKey() {
  //      return key;
  //  }
  //  
  //  @Override 
  //  public V getValue() {
  //      return value;
  //  }
  //  
  //  @Override
  //  public V setValue(V value) {
  //      V old = this.value;
  //      this.value = value;
  //      return old;
  //  }
  //  Map.Entry&lt;String, Object&gt; entry = new MyEntry &lt;String, Object&gt;(key, value);
  //  System.out.println(entry.getKey());
  //  System.out.println(entry.getValue());
  }
  
  
  
      }
  </code></pre>
  
  <p>attempt 2</p>
  
  <pre><code>public class readstringastext {
  
      public static HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
      public static void weightLimit() {
          String weightLimit = "";
          System.out.println(weightLimit);
  </code></pre>
  
  <p>// this is to see if the weightLimit is there which it isnt'.
          }</p>
  
  <p>public static void main(String[] args){</p>
  
  <pre><code>        try {
              File file = new File("test.txt");
              FileReader fileReader = new FileReader(file);
              BufferedReader bufferedReader = new BufferedReader(fileReader);
              String line;
              String weightLimit = "";
              boolean first = true;
              while ((line = bufferedReader.readLine()) != null) {
                  if (first) {
                      weightLimit = line;
                      first = false;
                  } else {
                      String[] values = line.split(" ");
                      map.put(values[0], values[1]);
                  }
              }
  
              fileReader.close();
          }       catch (IOException e) {
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>