Results 1 to 4 of 4
Thread: Two Objects
- 11-14-2008, 04:36 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 4
- Rep Power
- 0
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:
This prints values that appears on both elements and those that donot.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); }
I want to go furhter to do something like this:
Do anyone know how to go about 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 }Last edited by losintikfos; 11-14-2008 at 05:43 PM.
- 11-14-2008, 06:04 PM #2
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
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?
- 11-14-2008, 06:36 PM #3
Member
- Join Date
- Nov 2008
- Posts
- 4
- Rep Power
- 0
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.
- 11-14-2008, 07:04 PM #4
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
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 to 1 Objects
By this.that in forum New To JavaReplies: 4Last Post: 08-07-2008, 10:09 PM -
how many objects ?
By kevinsong in forum Advanced JavaReplies: 16Last Post: 07-16-2008, 05:59 PM -
Getting objects of a class
By ravian in forum New To JavaReplies: 1Last Post: 12-04-2007, 12:23 PM -
Help with Objects!
By Shorinhio in forum New To JavaReplies: 1Last Post: 07-10-2007, 09:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks