Results 1 to 6 of 6
  1. #1
    xpngamer is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default Set an Object Equal to Another Object

    Is there anyway to set an object equal to another object? Such as if I had an array of objects, is there any way to set object[1] = object[3]?

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

  3. #3
    kbindumadhavi is offline Member
    Join Date
    Apr 2009
    Posts
    20
    Rep Power
    0

    Default

    xpngamer,

    I did not get the question properly.
    Can you clarify whether you are asking about the comparison of two objects or you want to assign value to a object?

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    828
    Rep Power
    6

    Default

    Iam not getting ur question.But,if u want to check the equality this is the below method.

    Sample code

    class Sample
    {
    public static void main(String[] args)
    {
    //Test is a class and i have created 2 objects for Test and comparing.
    Test obj1 = new Test();
    Test obj2 = new Test();
    Test[] array1 = new Test[]{obj1};
    Test[] array2 = new Test[]{obj2};
    if(array1[0].equals(array2[0]))
    System.out.println("hi");
    }
    }

  5. #5
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    6

    Default

    Object.clone()?
    I die a little on the inside...
    Every time I get shot.

  6. #6
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2010, 02:12 AM
  2. Replies: 1
    Last Post: 03-04-2009, 06:14 PM
  3. Replies: 1
    Last Post: 07-22-2008, 04:27 PM
  4. Replies: 1
    Last Post: 04-17-2008, 10:10 PM
  5. Creating object of Type Object class
    By venkatv in forum New To Java
    Replies: 3
    Last Post: 07-17-2007, 03:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •