Results 1 to 6 of 6
  1. #1
    Angad is offline Member
    Join Date
    May 2016
    Posts
    3
    Rep Power
    0

    Default Compare previus record with current record in array list

    Hi,

    I have a sorted array list with 6 elements.The first 5 elements have some value, and the 6th one is empty.

    I want to loop through this ArrayList, and compare the first 5 elements of first record, with the same elements in next record. If any one of the element is different, then populate 6th element.

    Anyone know an easier and faster approach to do that?

    Thanks
    Angad

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Compare previus record with current record in array list

    I have a sorted array list with 6 elements.
    ...
    compare the first 5 elements of first record
    I'm not sure what you are asking. What is a record and what is an element?
    Can you post a simple sample of the data that you are trying to work with?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Angad is offline Member
    Join Date
    May 2016
    Posts
    3
    Rep Power
    0

    Default Re: Compare previus record with current record in array list

    following is example of my Arraylist
    Row1 : A1, B1, C1, D1, E1, ' '
    Row2: A1, B1, C1, D1, E2, ' '

    I need to compare values in first row with values in the next.
    In the above case, since E1 != E2, It means it is different, so need to generate a sequence number, and populate the 6th element of array which is currently blank.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Compare previus record with current record in array list

    generate a sequence number, and populate the 6th element of array which is currently blank.
    Ok, what would go in the 6th element?

    There needs to be better definitions for the data you are working with.
    Is an element a record?
    By Row1 do you mean the first record in the ArrayList?
    Is the contents of the record a String? For example the record's contents would be this String: "A1, B1, C1, D1, E1, ' ' "

    Or does the ArrayList contain Strings like these two lines:
    "Row1 : A1, B1, C1, D1, E1, ' '"
    "Row2: A1, B1, C1, D1, E2, ' '"
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Angad is offline Member
    Join Date
    May 2016
    Posts
    3
    Rep Power
    0

    Default Re: Compare previus record with current record in array list

    Let me explain a bit. Assume I have database table with 5 columns: Column1, Column2, Column3, Column4, Column5 And I have 3 records(rows) with the following values:
    A1, B1, C1, D1, E1
    A1, B1, C1, D1, E2
    A1, B1, C1, D2, E1
    I need to read this table into java, compare row by row, If column values in first row is different from second row, I will generate a sequence id, and populate another table with all the values , plus the sequence id in another database table.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Compare previus record with current record in array list

    What have you tried? Post some code that shows what you have tried and where you are having problems.
    The contents of each record needs to be separated into elements that can be compared with the contents of other rows.
    When there is a difference the code reacts as you have stated.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. How to remove an array record??
    By ProgRookie92 in forum New To Java
    Replies: 3
    Last Post: 07-18-2012, 04:35 PM
  2. Replies: 9
    Last Post: 07-09-2011, 08:15 PM
  3. Storing a record set into an array
    By DJCali in forum New To Java
    Replies: 2
    Last Post: 10-25-2009, 03:47 PM
  4. Replies: 0
    Last Post: 04-01-2008, 11:43 AM
  5. Replies: 0
    Last Post: 09-28-2007, 02:01 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
  •