Search a two-dimensional list or result set?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    Search a two-dimensional list or result set?

    Hi guys.

    I have a two-dimensional list. I need to see if a value is existing on the third column of each row. Just like searching a table with the third column as the index key.

    Do you read each row checking the specific column? Or is there a method or function that will do it.

    The value of this list is coming from a result set. Rather than keep on querying the sql-server, I am implementing it as a two-dimensional list. It's a limitation, so i don't have much choice.

    If there are no methods or function that will do the search on the list, then I have to read each row. Would it make sense then that I just read the search the result set, reading each row, than putting implementing this on a two-dimensional list?

    Thoughts?

    -- CK
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    Assuming you mean a 2D array, you'd be looping over matrix[i][2], I think. It would work similarly with la List, probably list.get(i).get (2). These snippets assume that I've got row/column down properly and that i is the loop counter.

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Yes, you're right.

      By the way you mention it, that would mean I have to loop and read each row until list.get(i).get (2) = 'myvalue' where i is a counter from 1 to size of the list. Am I right?

      If this is the case, would be better if I just read the result set?

      -- CK

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by ck9663
        Hi guys.

        I have a two-dimensional list. I need to see if a value is existing on the third column of each row. Just like searching a table with the third column as the index key.

        Do you read each row checking the specific column? Or is there a method or function that will do it.

        The value of this list is coming from a result set. Rather than keep on querying the sql-server, I am implementing it as a two-dimensional list. It's a limitation, so i don't have much choice.

        If there are no methods or function that will do the search on the list, then I have to read each row. Would it make sense then that I just read the search the result set, reading each row, than putting implementing this on a two-dimensional list?

        Thoughts?

        -- CK
        Yes, IMHO it is a very bad choice to implement an entire row of a table as a list
        that ends up in another list. Instead define a class that represents a row of a
        table so you finally end up with a single list of class objects.

        kind regards,

        Jos

        Comment

        Working...