title: Why my variable 'extra' is modified, while I am changing a copy of it.(Specific, not a general query)
body: <p>I am trying to solve  Bear and Steady Gene problem in HackerRank.
  I have an int array variable named extra, which I copy in extra_temp and do all modifications in this new variable, but somehow, original variable 'extra' is modified. I know it is strange but to be honest, I have spent hours to understand why this is happening but I can not find the reason for this. Here is my code</p>
  
  <pre><code>    public static int subFinder(int[] extra, char[] S, int N)
      {
  
      List&lt;Integer&gt; opt=new ArrayList&lt;Integer&gt;();
      int start=0;
      int end=0;
      int r=1;
      int[] extra_tmp=new int[4];
      for (int i=0;i&lt;N;i++)
      {
          extra_tmp=extra;
          //System.out.println(extra[0]);
          //System.out.println("");
          System.out.println(extra[1]);
          //System.out.println("");
          //System.out.println(extra[2]);
          //System.out.println("");
          //System.out.println(extra[3]);
          //System.out.println("Hello");
          int count=0;
  
          if(extra_tmp[S[i]-97]&gt;0)
          {
              start=i;
              extra_tmp[S[i]-97]--;
              for(int j=i+1;j&lt;N;j++)
              {  
                  if(extra_tmp[S[j]-97]&gt;0)
                  {
                      extra_tmp[S[j]-97]--;
                      end=j;
                  }
              }
  
                  System.out.println("Hello");
                      opt.add(end-start+1);
                      i=i+2;
          }
      }
      System.out.println(opt.size());
      Collections.sort(opt);
      r=opt.get(0);
      return r; 
  } 
  </code></pre>
  
  <p>I obtain the following output
  3
  Hello
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  0
  1
  10</p>
  
  <p>Here 3 is the value of extra[1] initially. What am I doing wrong?</p>
  
  <p>The remaining code is here</p>
  
  <pre><code>    public static void main(String[] args)
  {
      Scanner in=new Scanner(System.in);
      int N=in.nextInt();
      //System.out.println(N);
  
      in.nextLine();
      String s=in.nextLine();
      char[] S=new char[N];
      S=s.toCharArray();
      for (int i=0;i&lt;N;i++)
      {
          if (S[i]=='A')
              S[i]='a';
          else if (S[i]=='C')
              S[i]='b';
              else if (S[i]=='G')
              S[i]='c';
              else if(S[i]=='T')
              S[i]='d';
      }
      //System.out.println(S[0]);
      HashMap&lt;Character,Integer&gt; hm=new HashMap&lt;Character,Integer&gt;();
  
      hm.put('a',0);
      hm.put('b',0);
      hm.put('c',0);
      hm.put('d',0);
  
      for(int i=0;i&lt;N;i++)
      {
          hm.put(S[i],hm.get(S[i])+1);
      }
      //System.out.println(hm.get('A'));
      int[] count=new int[4];
  
      count[0]=hm.get('a');
      count[1]=hm.get('b');
      count[2]=hm.get('c');
      count[3]=hm.get('d');
  
      //System.out.println(count[0]);
  
      int[] extra=new int[4];
      for (int j=0;j&lt;4;j++)
      {          
          if (count[j]&gt;N/4)
          {
              extra[j]=count[j]-N/4;
              //System.out.println(extra[j]);
          }  
          else
              extra[j]=0;
  
      }
      for (int j=0;j&lt;4;j++)
      {    
          System.out.println(extra[j]);
      }
      //for (int l=0;l&lt;4;l++)
      //System.out.println(extra[l]);
      int r=subFinder(extra,S,N);
      System.out.println(r);
  }
  </code></pre>