The method clone() from the type Object is not visible - Answers given confuse me
<p>I know this question has been asked before, but everyone seems to give the same answer, put this:</p>

<pre><code> public Object clone(){  
 try{  
     return super.clone();  
 }catch(Exception e){ 
     return null; 
 }
}
</code></pre>

<p>into the class and add <code>implements Cloneable</code> to the class label and it should work. But it doesn't work in the case I am trying. My code is:</p>

<pre><code>            while (it.hasNext()) 
            {
                Map.Entry pair = (Map.Entry)it.next();
                for(int i = 0; i &lt; listOfString[k].size(); i++)
                {
                    String vals = listOfString[k].get(i);


                    if((vals).endsWith(pair.getValue().toString()))
                    {         

                        temp = vals.substring(0,29);
                        Object tempCopy = "";
                        tempCopy= temp.clone();

                        temp1[j][i] = Integer.parseInt(tempCopy.toString(),2);
                        System.out.println(temp1[j][i]);      // gives value if I use temp directly  - without cloning                   
                    }
                    temp ="";
                    System.out.println(temp1[j][i]); //gives 0 if i use temp directly - without cloning
                }
                j++;
                it.remove();
            }
</code></pre>

<p>Basically, I have a <code>map</code> with <code>&lt;String, Int&gt;</code> key value pairs and an <code>ArrayList</code> of <code>Strings</code>. The important part of this question is that I'm trying to put <code>integer</code> values into my <code>array</code> temp1. Since Java passes by reference and I don't want my <code>temp</code> string to get reset, I used the <code>.clone()</code> method. I still get the error in the title of this question inspite of doing what people have said. Also, in case someone has an answer on how to make sure that <code>temp1</code> does not lose values when I reset <code>temp</code> to <code>""</code>, I would appreciate it.  </p>