Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Swapping of two Integer Variables !!! Very Strange !!!!!

807606Mar 26 2007 — edited Mar 26 2007
Hi All,

Following code is supposed to swap integer values..
but it is not happening

  
public class Swap {
    
  public static void swap(Integer a, Integer b){
        Integer tmp = new Integer(a.intValue());
        a = b;
        b = tmp;
        System.out.println("A : "+ a +  "B : "+b);
        
    }

    public static void main(String[] args) {
        Integer a = new Integer(10);
        Integer b = new Integer(20);
        
        swap(a,b);
        
        System.out.println("A : "+ a +  "B : "+b); 
    }
}
WHY ?????

Thanks in Advance
Krishna
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 23 2007
Added on Mar 26 2007
12 comments
245 views