title: Why isn't my text file reading in Java Eclipse as a String?
body: <p>I'm a beginner in Java Eclipse. I am trying to read a .txt file, and use the data as a String value. However, when I use an <code>if</code> statement, the condition is not registering the value as a String and is therefore not meeting any conditions and I am only getting the final <code>else</code>.</p>
  <p>The purpose of my code is to read in a text file and determine the required value: i.e. if the line starts with &quot;avg&quot; , the program must display the average of the following numbers.</p>
  <p>My .txt file contents is this:</p>
  <p>min:1,2,3,4,5,6\n
  max:1,2,3,4,5,6\n
  avg:1,2,3,4,5,6</p>
  <p>Here is a part of my code:</p>
  <pre><code>public static void main(String[] args) throws IOException {
      
      //declare variables
      String line, operation;
      int min, max, sum, num;
      double avg;
      List&lt;String&gt; lineArray;
      String outputPath = &quot;C:\\output.txt&quot;;       //these are not the actual file paths, i just didnt 
      String inputPath = &quot;C:\\input.txt&quot;;         //want to give personal information.
  
      //try open file
      try {
          
          //create File instance  
          File text = new File (inputPath);   
          Scanner scnr = new Scanner(text);                               
  
          //loop until end of text file
          while ( scnr.hasNextLine() ) {
                              
              line = scnr.nextLine();                  //read line from text file
              operation = line.substring(0,3);         //get operation from String data
              
              line = line.substring(4);                //get String value of numbers              
              lineArray = Arrays.asList(line.split(&quot;,&quot;));     //separate string into array elements
  
              //setup initial values
              sum = 0;
              min = Integer.parseInt(lineArray.get(0));     //convert to Int
              max = Integer.parseInt(lineArray.get(0));
              
              //loop through line array and determine min, sum and max of each
              for (int i = 0; i &lt; lineArray.size(); i++ ) {
                  
                  num = Integer.parseInt(lineArray.get(i));
                  sum += Integer.parseInt(lineArray.get(i));
                  if (num &gt; max)  max = num;
                  if (num &lt; max)  max = num;
                  
              }
              
              avg = sum / lineArray.size();   
              
              //the IF condition statement that is not working                
              if (operation  == &quot;min&quot;) {
                  System.out.println(min);
              }
              
              else if (operation == &quot;max&quot;) {
                  System.out.println(max);
              }
              
              else if (operation == &quot;avg&quot;) {
                  System.out.println(avg);
              }
              
              else System.out.println(&quot;Error&quot;);
              
          }   //end of while loop
          
          scnr.close();                                                       //close scanner
          
      }   //end of try
      
      catch ( FileNotFoundException e ) {
      }
      
  }   //end of &quot;main&quot; class
  </code></pre>
  <p>When I manually set operation as &quot;min&quot; or &quot;max&quot; or &quot;avg&quot; the program works as it should.</p>