Comparing integer with array list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • frozenade
    New Member
    • Nov 2007
    • 23

    Comparing integer with array list

    Hello..

    I need to compare an integer value with array list.
    Code:
    Code:
            if (year > 1986) {
                Integer[] twelve = {1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986};
                while (year != twelve) {
                    year -= 12;
                }            
            }
    The code is very bad.

    Would somebody please help me?

    Thank you.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by frozenade
    Hello..

    I need to compare an integer value with array list.
    Code:
    Code:
            if (year > 1986) {
                Integer[] twelve = {1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986};
                while (year != twelve) {
                    year -= 12;
                }            
            }
    The code is very bad.

    Would somebody please help me?

    Thank you.
    An arraylist is a container that holds other objects. Comparing it with an integer does not really make logical sense. You also don't happen to have an arraylist in that code you have there. What you have is an Integer array.
    Perhaps you want to test if an integer is present in an array?

    Comment

    • samido
      New Member
      • Oct 2007
      • 52

      #3
      can you please post a seudo code for you problem, it happened to you to know a java objects without knowing theire uses, what are you trying to solve infect?

      Comment

      • frozenade
        New Member
        • Nov 2007
        • 23

        #4
        oh, I got it.

        I could compare it by made a loop to retrieve each of array index then compare with the integer.

        Yes, it's true, comparing an integer with arrays is really ridiculous. Forgive me for my bad. :)

        Thank you very much for helps.

        Best regards.

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by frozenade
          oh, I got it.

          I could compare it by made a loop to retrieve each of array index then compare with the integer.

          Yes, it's true, comparing an integer with arrays is really ridiculous. Forgive me for my bad. :)

          Thank you very much for helps.

          Best regards.
          Yep, you've got it now.

          Comment

          Working...