title: Java function calling and return value in Android
body: <p>I have a Java class with some code to be operated based on flag value, below is my code which works as flag value is 1</p>
  
  <pre><code>if(flag==1)
  {
      Log.d("Flag value", "flag= "+flag);
      System.out.println("Read have "+read());
      String tt=read();
      s1=tt;
  }
  </code></pre>
  
  <p>From this above function the value in the variable "s1" is some string value returned by read() function.</p>
  
  <p>the output of this code is returning two times of read() function, like</p>
  
  <p>s1 having "StringString"</p>
  
  <p>Here is my read function code</p>
  
  <pre><code>public String read(){
  
            try{
               FileInputStream fin = openFileInput(file);
               int c;
  
               while( (c = fin.read()) != -1)
               {
                  temp = temp + Character.toString((char)c);
               }
            }
            catch(Exception e)
            {
  
            }
            Log.d("INSIDE READ FUNC", "temp have "+temp);
          return temp;
         }
  </code></pre>
  
  <p>While I omitted this "System.out.println("Read have "+read());" by below code</p>
  
  <pre><code>if(flag==1)
      {
          Log.d("Flag value", "flag= "+flag);
          //System.out.println("Read have "+read());
          String tt=read();
          s1=tt;
      }
  </code></pre>
  
  <p>And I got the perfect output like </p>
  
  <p>s1 having "String"</p>
  
  <p>How come the code works like this? I called the read() function only once to store to "tt" variable.</p>
  
  <p>And storing the tt variable to s1 variable.</p>
  
  <p>But when I use System.out.println("Read have "+read()); its invoking and storing the returned string value in array and in the second time I am storing to the "tt" String variable and its appending the last returned string from the read() function to the "tt" String variable.</p>
  
  <p>So the "tt" String variable having two times of read() function Returned String.
  How it is storing two times?</p>