How to exclude exisiting objects when combining ArrayLists?

Hi there, I'm new to Java and im trying to find a way to combine 2 ArrayLists and exclude any objects that may already exist in the customer ArrayList. I have a program that loads/saves data from a text file into a class object and I want the function to load the data 1 time and check if it already exisits.
I have tried using if(!customers.contains(obj)), but I think this only references the ArrayList Key and not the actual data.
Below is a test class I have been using to debug. Any help would be great!!!
public class test {
     public static void main(String[] args){
          ArrayList<Customer> temp  = new ArrayList<Customer>();
          ArrayList<Customer> customers  = new ArrayList<Customer>();
          Customer cs1 = new Customer(1,"sophie",'m',23,"asdasd");
          Customer cs2 = new Customer(1,"sophie",'m',23,"asdasd");
          Customer cs3 = new Customer(2,"asd",'m',23,"sdfghh");
          Customer cs4 = new Customer(3,"sdfff",'m',23,"hhhrrr");
          temp.add(cs1); temp.add(cs3); temp.add(cs4);
          customers.add(cs2);
          for(Customer c : temp){
               if(!customers.contains(c))
               customers.add(c);
          Collections.sort(customers, new CustomerComparator());
          System.out.println(customers);
          System.out.println(customers.contains(cs2));
}Edited by: newToJavaPro on May 21, 2010 10:18 PM

paulcw wrote:
newToJavaPro wrote:
Thanks for your reply I tried using a HashSet, which works for removing objects from the same origin, but it doesn't seem to remove the same data when added to the ArrayList from different objects. For example, id like to use cs1 to remove an instance of cs2 as they contain the same data but are assigned using different objects.No, that doesn't make any sense. More likely, you didn't properly override .equals() and hashcode(), so the set can't compare them properly. It seems to happen when they come "from different objects" because you're creating different instances of Customer each time, so the default implementations of .equals() and .hashcode() identify them as non-equivalent.Thanks, I I didn't realize HashSet and Equals compared object instance by default. Overridden methods and works a treat.

Similar Messages

  • How to exclude deleted objects when merging CRs?

    Dear gurus,
    we are using se03 to merge several CRs into a big one, but the problem is
    the deleted objects are merged too, which cause alot of error message when trying to save .
    could you pls tell me how to solve this ?
    br
    zj

    Please be clear what do mean by deleted objects Also if you merge the CRs into one you can easliy remove the objects you donot want from respective CR.

  • How to exclude sales office for combination sales order type/division?

    Hi experts,
    I would appreciate if you could advise: How to exclude sales office for combination sales order type/division in ECC 6.0 ?

    Hi
    Standard SAP functionality would not be able to cater to this. Ideally create a Z table with sales order type and sales office combination. Put in entries for combinations that are allowed. In Sales order program MV45AFZZ use the exit USEREXIT_MOVE_FIELD_TO_VBAK. In this exit write down the logic passing the sales office determined and the order type and check if the entry is there or not. If the entry is there then it should go on to the next step. If it does not then pass an error message. You need to use the help of your ABAP er for this.
    Thanks
    Indranil

  • How to create and object from an arrayList

    Hi I want to create an object from an arrayList.
    here is my code...
    BillingQueryParam billingQueryParam = new BillingQueryParam();
    /*This BillingQueryParam and billingItemManagerActionForm has getter and setter method for following attributes.
    private int billingItemId;
    private String[] paramName;
    private String[] defaultParamValue;
    List billingQueryParamList = new ArrayList();               
    for(int i = 0; i < billingItemManagerActionForm.getParamName().length; i++) {
         billingQueryParam.setParamName(billingItemManagerActionForm.getParamName());
    for(int i = 0; i < billingItemManagerActionForm.getDefaultParamValue().length; i++) {
      billingQueryParam.setDefaultParamValue(billingItemManagerActionForm.getDefaultParamValue());
         billingQueryParam.setBillingItemId(billingItem.getBillingItemId());
         billingQueryParamList.add(billingQueryParam);
    System.out.println("****** ArrayList Size-->"+billingQueryParamList.size());
    for (Iterator iter = billingQueryParamList.iterator();iter.hasNext();) {
         billingQueryParam = (BillingQueryParam)iter.next();
          System.out.println("****** BillingItemId-->"+billingQueryParam.getBillingItemId());
          System.out.println("****** Param Name-->"+billingQueryParam.getParamName()); //printing an array of paramName
          System.out.println("****** Default param value-->"+billingQueryParam.getDefaultParamValue());
    }Here after iterating this list I want to create an object of billingQueryParam which contains a single value of itemId, paramName,paramTypeId and defaultParamName and I want to persist this object in database.
    Please help...!!!
    Thanks

    Now this is too much.. Do i need to tell this thing to u as well. How did u come to this forum?
    Can't u see link to Java programming forum at the top.

  • How to create lock object  when the total length is more than 300bytes?

    Dears:
    I want to create lock object for a add-on table , and the total length of  table's fields is more than 300 bytes.
    When I acitve this object, it will show "Total length of lock argument for table ZTEST_XXX longer than 300" error message in log.
    Is there any way  which can create  lock object when total length > 300bytes? 
    Thanks in advance.
    Best regards
    Lily

    Hi, Sudhi Karkada Sandeep Kumar 
    Thank you very much for your help.
    When the total length of  keys is more than 150bytes, lock object can't be created.
    Best regards,
    Lily

  • How to exclude a table when doing dbcc checkdb

    when running dbcc checkdb(mydb). it will go through all tables. Is it possible to exclude a table from dbcc checkdb?

    Thanks, Mark. When I run dbcc checkdb(mydb), it across a table and take over 18 hours and still waiting.
    the message is:
    Checking mytable: Logical pagesize is 2048 bytes
    The total number of data pages in this table is 1365692.
    The total number of pages which could be garbage collected to free up some space is 2923.
    then I stop it manually.
    Possibly something wrong with the table. When I run dbcc checktable on this table, it' also keep me waiting and never end. then I can't finish dbcc checkdb because of this table. the size of this table is about 3G. How to resolve this problem?

  • How to create Entity Object when connecting JavaDB in Jdev 11g

    I use Jdev 11g to connect JavaDB. When I use the BC4J wizard to create EO and VO, I only can see VO, the EO is empty.
    any ideas?
    Thanks

    In the Application Navigator, right-click the project in which you want to create the entity object and choose New.
    In the New Gallery, expand Business Tier, select ADF Business Components and then Entity Object, and click OK.
    If this is the first component you're creating in the project, the Initialize Business Components Project dialog appears to allow you to select a database connection.
    In the Initialize Business Components Project dialog, select the database connection or choose New to create a connection. Click OK.
    On the Name page, do the following to create the entity object:
    Enter the package name in which the entity object will be created.
    Click Browse (next to the Schema Object field) to select the table for which you want to create the entity object.
    Or, if you plan to create the table later, you can enter a name of a table that does not exist.
    If you manually entered a table name in the Schema Objects field, you will need to define each attribute on the Attributes page of the wizard. Click Next.
    When you are satisfied with the table object and its corresponding entity object name, click Finish

  • How to Exclude a directory when doing the JAR

    Suppose I have directory x, x/y, ....
    I want to jar only x and not the subdirectory y.
    By default it will be jar all the subdirectories, how
    to over-ride that or exclude some of the sub-directories.

    You can use the -C option to temporarily change directories, but otherwise there is no option for exclusion. You could use a utility like WinZip to prune excess files/directories if need be.
    -Ron

  • How to exclude VIP email when sent to a specific email

    I would like to make a rule for a VIP contact who I communicate with personally and for work. I have all of her emails all mixed in my VIP box. I do have a work email address set up to check in mail. I would like to exclude emails sent to that address only, from showing up in the VIP folder. Is there a way to do that? I did not see anything in the message rules that looked like you could make a rule about the VIP folder.

    I am not aware of any such e-mail notification. You can configure a machine with one of the older JRE versions to receive a notification when a new JRE version is made available for download. Use the Java Control Panel for this.

  • How to replace all existed objects when impdp a schame ???

    I wrote 2 functions which do expdp and impdp
    the impdp funciton is :
    create or replace function impdp_schema(fromusr in varchar2,
                                            tousr   in varchar2,
                                            dir     in varchar2,
                                            dmpfile in varchar2,
                                            logfile in varchar2 default null)
      return number as
      h1        NUMBER;
      job_name  varchar2(128);
      job_state varchar2(32767);
      ret       number;
    BEGIN
      if dir is null or dmpfile is null then
        return 1;
      end if;
      ret := 0;
      job_name := 'IMP' || to_char(sysdate, 'yyyymmddhh24miss');
      h1 := DBMS_DATAPUMP.OPEN('IMPORT',
                               'SCHEMA',
                               NULL,
                               job_name,
                               'COMPATIBLE',
                               DBMS_DATAPUMP.KU$_COMPRESS_METADATA);
      DBMS_DATAPUMP.ADD_FILE(h1,
                             dmpfile,
                             dir,
                             null,
                             DBMS_DATAPUMP.KU$_FILE_TYPE_DUMP_FILE);
      if logfile is not null then
        DBMS_DATAPUMP.ADD_FILE(h1,
                               logfile,
                               dir,
                               null,
                               DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE);
      end if;
      DBMS_DATAPUMP.METADATA_REMAP(h1,
                                   'REMAP_SCHEMA',
                                   UPPER(fromusr),
                                   UPPER(tousr));
      DBMS_DATAPUMP.set_parameter(h1, 'TABLE_EXISTS_ACTION', 'REPLACE');
      DBMS_DATAPUMP.START_JOB(h1);
      dbms_datapump.wait_for_job(h1, job_state);
      dbms_datapump.detach(h1);
      dbms_output.put_line(job_state);
      return ret;
    exception
      when others then
        dbms_output.put_line(SQLERRM);
        dbms_datapump.detach(h1);
        return 1;
    END;------------------------------------
    when I test this function, I found some errors :
    Master table "SYS"."IMP20100823152536" successfully loaded/unloaded
    Starting "SYS"."IMP20100823152536": 
    Processing object type SCHEMA_EXPORT/USER
    ORA-31684: Object type USER:"WIS00001" already exists
    Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
    Processing object type SCHEMA_EXPORT/ROLE_GRANT
    Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
    Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
    Processing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCE
    ORA-31684: Object type SEQUENCE:"WIS00001"."SEQ_ID_WIS_LOG" already exists
    ORA-31684: Object type SEQUENCE:"WIS00001"."SEQ_TID_TABLENAME" already exists
    ORA-31684: Object type SEQUENCE:"WIS00001"."SEQ_WIS_MASS" already exists
    ORA-31684: Object type SEQUENCE:"WIS00001"."SEQ_WITSDELAY_1" already exists
    ORA-31684: Object type SEQUENCE:"WIS00001"."SEQ_WITSDELAY_2" already exists
    ORA-31684: Object type SEQUENCE:"WIS00001"."SEQ_WITSDELAY_3" already exists
    ORA-31684: Object type SEQUENCE:"WIS00001"."SEQ_WITSEDIT" already exists
    Processing object type SCHEMA_EXPORT/TABLE/TABLE
    Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
    . . imported "WIS00001"."WITS_98_PIC"                    28.28 KB      97 rows
    . . imported "WIS00001"."DRAWING_CONTROL"                26.94 KB     218 rows
    Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
    Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
    Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
    Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
    ORA-31684: Object type PROCEDURE:"WIS00001"."PROC_GETITEM" already exists
    Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
    Processing object type SCHEMA_EXPORT/TABLE/TRIGGER
    **Job "SYS"."IMP20100823152536" completed with 9 error(s) at 15:30:12**---------------
    how to replace all objects when exist ??? include sequence, table, procedure/function???
    </pre>
    Edited by: UNISTD on 2010-8-23 上午12:50

    I love posts without a 4 digit version number. This may well be because of a bug, and as this post is lacking a 4 digit version number, nobody will be able to answer it.
    You posted in vain.
    I recommend you search on Metalink whether there are issues with this parameter.
    Sybrand Bakker
    Senior Oracle DBA

  • How to suppress compiler errors without excluding database objects from the "Schema Compare" tool (using VS2013/SSDT)

    Hi,
    In short: How to suppress compiler errors without excluding the object from the "Schema Compare" tool ??
    A bit longer:
    We have a SQL Server 2008 project in Visual Studio 2013 running SQL Server Data Tool.
    An old database, with a lot of history in, has been imported into SSDT and there are many syntax errors preventing the project from compiling/running. An typical error is: "SQL70001: This statement is not recognized in this context".
    Running the "faulty" scripts on the server, executes just fine. I understand that there are syntax errors and they should be rewritten, but it's not gonna happen just like that - it is a slow process over a long period of time.
    I know it is possible to change Build Action to None, but that also exclude the object from appearing in the Schema Compare function/window.
    So - how to ignore some compiler errors and still having the objects to appear when doing "Schema Compare" ??
    Thank you in advance.

    Hi Steven,
    Thanks for your comments.
    Well, it sure does help in the future, but right now i would prefer the other way - to suppress some errors and still allow the scripts to build.
    The thing is that if we "rewrite" the objects into create scripts, then we have a huge test job ahead of us + the database environments (PROD vs DEV and UAT) does not share the same AD or DB users and therefore grants is lost if dropping/creating
    objects, right!
    If you drop a object before creating it, the drop will also drop the roles and grants and since they don't share user table, the create will not be able to add the permissions again. There might be a solution to that, but it is going to be very complicated
    for some newbies like us. We need something we can trust.
    BR
    Peter

  • How to retain numerical order (Of file names) when combining files in Acrobat (9) Standard

    How to retain numerical order (Of file names) when combining files in Acrobat (9) Standard, please see the attached screenshot for a clearer explanation.
    I understand that if we prefix all files with leading zero's this will probably resolve the issue but I just wondered if anyone new the answer. The ironic situation is that version 6 has no problem.
    I have spent over an hour with techincal support who were unable to provide me with an answer

    It is not clear how you are trying to do the order. Have you tried to select a set of files and then use the arrow buttons to move them in the list? If you select the heading, that will typically reorder the files by that heading and undo everything you had done before.
    You should be able to select groups of files and move them up and down in the list. All of those options appear on your view, so what is the real question?

  • "In Adobe Standard, when combining files into one pdf, how do I keep the original date"?

    I converted multiple emails into a pdf file.  After opening the pdf file, I wanted to combine the files into one pdf however once combining the files, the date modified of the files changes to the current date.  How do I preserve the original dates of the emails when combining the files?

    Hi Softball ,
    Thank You for posting on the forums. Apparently there is no such feature that would help you to achieve this.
    Thanks,
    Vikrantt Singh

  • Acrobat X Standard Bookmarks - How do I make the Zoom Level action default to "Fit Page" when combining to one pdf?

    Acrobat X Standard Bookmarks - How do I make the Zoom Level action default to "Fit Page"?
    When I combine multiple pdf files into a single binder, Acrobat creates a bookmark for each file.  In the properties for each bookmark, there is an action created to go to the page in the document and has the zoom level at "fit width".  Question is, how do I change this apparent default zoom level to "fit page" when Acrobat creates the bookmarks when combining the pdf files?

    Is there a way to do it in one step instead of individually on each bookmark?  This gets VERY cumbersome when I have upwards of a hundred bookmarks to change.

  • File is huge when combined or changed to PDF, how do I get the file to a normal size to print?

    Files are to large to print once they are PDF, how do I get them to a normal 8x11 size to print?

    So why is it when I send these PDF files to clients they are to large for clients to print?
    If I send a combined PDF file that is 3817KB, which a client has said is to large for them to print.
    I send it to our office manager, she will print it, scan it back to me as a PDF, it will come
    back as 375KB, the client can then print the file.
    My question is, was/is there something I need to change in the process of scanning, combining files
    to PDF that would create a smaller size file when done?
    Sorry for all the confusion
    Marilyn Bartunek
    Juffer Real Estate Inc.
    605-360-7703
    [email protected]
    Date: Tue, 1 Apr 2014 10:13:35 -0700
    From: [email protected]
    To: [email protected]
    Subject: file is huge when combined or changed to PDF, how do I get the file to a normal size to print?
        Re: file is huge when combined or changed to PDF, how do I get the file to a normal size to print?
        created by Test Screen Name in Creating, Editing & Exporting PDFs - View the full discussion
    Sorry, I'm lost.First I thought this was about page size. But you say it isn't. You say it's about file size.  You've combined files of 494 + 441 = 935 KB, and you get 944 KB. This seems fine and you say it is fine. So what is the problem? Are you now on still a third meaning of huge, about size on screen?
         Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/6261540#6261540
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/6261540#6261540
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/6261540#6261540. In the Actions box on the right, click the Stop Email Notifications link.
               Start a new discussion in Creating, Editing & Exporting PDFs at Adobe Community
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

Maybe you are looking for

  • How do I create a new account on Ziio space?

    Hi. I'm a new user of the Ziio0 and I want to know where I can create an account to be able to login to? http://www.creative.com/ziiospace/ and use some of the apps listed there. Thanks....

  • Using Oracle Users in Realms and DataSource.getConnection

    Is it possible to authenticate using an Oracle User via JAASRealm and also retrieve connections specific to that user from a DataSource? I currently have an application which doesn't use either, but rather sets up a OracleDataSource. So basically I j

  • No image preview

    So I accidentally crashed my system by attempting to get my system to run in 64 bit mode and failed, severely. My boot file was messed up and I just couldn't fix it so I did a time machine restore. But thats all behind me now, and ALMOST everything w

  • Metrics on database read/write/delete based on size of the table

    Hi, Though we have many performance measurement tools,sometimes it is difficult for developers to trace and measure each read, some reads which look fine in the development environment turn out to be show stoppers in quality environments. I am trying

  • Pixma MX860 shows an error 9000

    Cannon MS860 printer shows an error 9000 on screen, I followed Instruction to turn it off then back on and get the same error.  The manual gives no help.  Any suggestions from out there?