Results 1 to 4 of 4

Thread: Two Objects

  1. #1
    losintikfos is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Default Two Objects

    Hi Guys,

    I have two Objects, Customer and Sites. I want to go through each objects list and select element values that can be found on the two objects.

    for example:
    PHP Code:
    Collection<String> inBothTables = new ArrayList<String>(SiteName);
    Collection<String> notInBothTables = new ArrayList<String>(inBothTables);
    if (inBothTables.retainAll(compName)) {
    System.out.println("Direct: " + inBothTables);
    				
    } 
    if (notInBothTables.removeAll(inBothTables)) {
    				
    System.out.println("Operator: " + notInBothTables);
    }
    This prints values that appears on both elements and those that donot.

    I want to go furhter to do something like this:

    Java Code:
    If value can be found inBothTables {
      //PRINT I AM FOUND ON THIS I CAN NOW BE USE FOR SOMETHING
    }else if value can be found in notInBothTables{
    //PRINT I AM FOUND ON HERE I CAN  BE USE FOR SOMETHING
    }
    Do anyone know how to go about this?
    Last edited by losintikfos; 11-14-2008 at 05:43 PM.

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    It's hard to understand what the problem is. You already have a Collection for items "in both tables" and a Collection for items "not in both tables". Why do you need if-statements?

  3. #3
    losintikfos is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Default

    I have to insert different values to a database table base on the condition. for example:

    If value can be found inBothTbles{
    //INSERT A TO TABLE
    }
    else if Value isNotInBothTable{
    //INSERT B TO TABLE
    }

    I have a method which does the insert to the database, all i want now is to have a comon variable decribing whether to insert A or B which can be passed to the query. I am having a tuff time with the condition statement.

    Hope this helps.

  4. #4
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    I'm assuming that your two Collection objects from the first chunk of code correctly contain what is "in both tables" and "not in both tables" to be used in your second chunk of code. Correct me if I'm wrong.

    If this is true, can't you just dump the contents of both Collection objects? Are you needing to traverse through the items in each list? If so, you need to use get an Iterator from each Collection and read up on how to use it.

    Sorry if I'm not understanding, I'm not too sure what your code is trying to do.

Similar Threads

  1. 1 to 1 Objects
    By this.that in forum New To Java
    Replies: 4
    Last Post: 08-07-2008, 10:09 PM
  2. how many objects ?
    By kevinsong in forum Advanced Java
    Replies: 16
    Last Post: 07-16-2008, 05:59 PM
  3. Getting objects of a class
    By ravian in forum New To Java
    Replies: 1
    Last Post: 12-04-2007, 12:23 PM
  4. Help with Objects!
    By Shorinhio in forum New To Java
    Replies: 1
    Last Post: 07-10-2007, 09:32 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
  •