java.util.List

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #31
    Originally posted by shana07
    From what I understand your question is yes!
    But if I track the 'equals' method declaration from my netbeans, it's not pointed to 'equals' what we put in the Entry class. It points to 'equals' in java/lang/Object.java(r/o) .
    Maybe that's the reason why I don't get right comparison answer
    That's because we did not override the equals method. Instead we overloaded the equals method with another. Change that equals method's signature to
    Code:
     public boolean equals(Object e)

    Comment

    • shana07
      Contributor
      • Jan 2007
      • 280

      #32
      Originally posted by r035198x
      That's because we did not override the equals method. Instead we overloaded the equals method with another. Change that equals method's signature to
      Code:
       public boolean equals(Object e)
      Code:
       cannot find symbol
          [javac] symbol  : variable value
          [javac] location: class java.lang.Object
          [javac] return value != e.value;
      java.lang.Error: Unresolved compilation problem: 
      	e.value cannot be resolved or is not a field

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #33
        Originally posted by shana07
        Code:
         cannot find symbol
        [javac] symbol : variable value
        [javac] location: class java.lang.Object
        [javac] return value != e.value;
        java.lang.Error: Unresolved compilation problem: 
        	e.value cannot be resolved or is not a field
        You'd of course then have to type cast the Object to Event to make that work.

        Code:
         public boolean equals(Object e) { 
         Event event = (Event)e;
        ......

        Comment

        • shana07
          Contributor
          • Jan 2007
          • 280

          #34
          sorry, I still don't get the right answer.
          I'll update again. thanks for your help.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #35
            Originally posted by shana07
            sorry, I still don\'t get the right answer.

            I\'ll update again. thanks for your help.
            Like this

            Code:
             public boolean equals(Object e) 
            { 
            
             return value != ((Entry)e).value;
            }


            What errors are you still getting?

            Comment

            • shana07
              Contributor
              • Jan 2007
              • 280

              #36
              dear friend,
              your code works fine.TQ.
              Take a look at this it seems mine & yours not much different at glance..hurm
              Code:
              public boolean equals(Object e)  
                 { 
                    Entry entry = (Entry)e;          
                    return value != entry.value;    
                 }
                 
                  public boolean equals(Object e) 
                  { 
                   return value != ((Entry)e).value;
                  }

              Comment

              • shana07
                Contributor
                • Jan 2007
                • 280

                #37
                Friend,
                I have other doubt about Lists..please advise.
                Is it possible for me to get a Lists with many sub_Lists?
                Meaning, under same 'ifs1' field has many ifs1[i], ifs1[2] and etc....Take a look at this:
                Code:
                java.util.List ifs = new java.util.ArrayList(); ---> this field with ifs.size()=4 and no change.
                
                java.util.List ifs1 = new java.util.ArrayList(); ---> this field with ifs1[i].size()=4
                ifs1[ii].size=4, .......will increase more & more.
                The reason why i'm getting this because
                1. I want to make sure/remain the size for ifs1 & 'ifs' is SAME (4)

                At this moment, I don't think about the need to create more Lists (because it can be too many Lists),
                if you think that I do need, then how to get that in efficient way....thank u

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #38
                  Originally posted by shana07
                  dear friend,
                  your code works fine.TQ.
                  Take a look at this it seems mine & yours not much different at glance..hurm
                  Code:
                  public boolean equals(Object e) 
                  { 
                  Entry entry = (Entry)e; 
                  return value != entry.value; 
                  }
                   
                  public boolean equals(Object e) 
                  { 
                  return value != ((Entry)e).value;
                  }
                  Both should work the same way.

                  Comment

                  • shana07
                    Contributor
                    • Jan 2007
                    • 280

                    #39
                    Originally posted by r035198x
                    Both should work the same way.
                    Noted. Could you please take a look at my above post. I have other doubt about this Lists please.

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #40
                      Originally posted by shana07
                      Friend,
                      I have other doubt about Lists..please advise.
                      Is it possible for me to get a Lists with many sub_Lists?
                      Meaning, under same 'ifs1' field has many ifs1[i], ifs1[2] and etc....Take a look at this:
                      Code:
                      java.util.List ifs = new java.util.ArrayList(); ---> this field with ifs.size()=4 and no change.
                       
                      java.util.List ifs1 = new java.util.ArrayList(); ---> this field with ifs1[i].size()=4
                      ifs1[ii].size=4, .......will increase more & more.
                      The reason why i'm getting this because
                      1. I want to make sure/remain the size for ifs1 & 'ifs' is SAME (4)

                      At this moment, I don't think about the need to create more Lists (because it can be too many Lists),
                      if you think that I do need, then how to get that in efficient way....thank u
                      I'll be frank here. I did not understand all that. All I can say is an ArrayList can contain other lists as elements as well.

                      Code:
                       ArrayList list = new ArrayList(); 
                      list(0) = new ArrayList();
                      Or
                      Code:
                      ArrayList<ArrayList> lists = new ArrayList<ArrayList>();

                      Comment

                      • shana07
                        Contributor
                        • Jan 2007
                        • 280

                        #41
                        Originally posted by r035198x
                        I'll be frank here. I did not understand all that. All I can say is an ArrayList can contain other lists as elements as well.

                        Code:
                         ArrayList list = new ArrayList(); 
                        list(0) = new ArrayList();
                        Or
                        Code:
                        ArrayList<ArrayList> lists = new ArrayList<ArrayList>();
                        :) at least thanks for reading my problem.

                        From the code, what's mean for list[0]?
                        How about these codes, what's the difference?
                        Code:
                         List ifs = new ArrayList();  vs.  ArrayList ifs = new ArrayList();
                        If you have an example how to use the ArrayList, please share with me.

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #42
                          Originally posted by shana07
                          :) at least thanks for reading my problem.

                          From the code, what's mean for list[0]?
                          How about these codes, what's the difference?
                          Code:
                           List ifs = new ArrayList(); vs. ArrayList ifs = new ArrayList();
                          If you have an example how to use the ArrayList, please share with me.
                          Code:
                          List ifs = new ArrayList();
                          the ArrayList is stored in a variable of type List. Any calls to static variables call variables in the List interface. You can also assign other type of Lists e.g LinkedList to be stored by the variable ifs whereas with
                          Code:
                          ArrayList ifs = new ArrayList();
                          you cannot make ifs store a reference to any object of type that is not a subclass of ArrayList. You'll probably not be able to notice the difference.

                          Comment

                          • shana07
                            Contributor
                            • Jan 2007
                            • 280

                            #43
                            Originally posted by r035198x
                            Code:
                            List ifs = new ArrayList();
                            the ArrayList is stored in a variable of type List. Any calls to static variables call variables in the List interface. You can also assign other type of Lists e.g LinkedList to be stored by the variable ifs whereas with
                            Code:
                            ArrayList ifs = new ArrayList();
                            you cannot make ifs store a reference to any object of type that is not a subclass of ArrayList. You'll probably not be able to notice the difference.
                            I've tried run program by replacing
                            Code:
                            ArrayList ifs1 = new java.util.ArrayList();
                            in my program, yes I can't see the difference. the entries are the same.
                            you cannot make ifs store a reference to any object of type that is not a subclass of ArrayList.
                            What's the subclass here mean?

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #44
                              Originally posted by shana07
                              I've tried run program by replacing
                              Code:
                              ArrayList ifs1 = new java.util.ArrayList();
                              in my program, yes I can't see the difference. the entries are the same.
                              you cannot make ifs store a reference to any object of type that is not a subclass of ArrayList.
                              What's the subclass here mean?
                              A class that inherits from the class ArrayList. (That's if you know any inheritance)

                              if you have
                              Code:
                               class B { 
                              }
                              and
                              Code:
                               class A extends B { 
                              }
                              You can do
                              Code:
                              B b = new A();
                              but you cannot do
                              Code:
                               A a = new B();
                              In this case your B is list and your A is ArrayList except for that List is actually an interface rather than a class.

                              Comment

                              • shana07
                                Contributor
                                • Jan 2007
                                • 280

                                #45
                                Originally posted by r035198x
                                A class that inherits from the class ArrayList. (That's if you know any inheritance)
                                if you have
                                Code:
                                 class B { 
                                }
                                and
                                Code:
                                 class A extends B { 
                                }
                                You can do
                                Code:
                                B b = new A();
                                but you cannot do
                                Code:
                                 A a = new B();
                                In this case your B is list and your A is ArrayList except for that List is actually an interface rather than a class.
                                TQ.Pretty understood List now and also I read List is an interface from a Collection.
                                Then, how about an ArrayList can contain other lists .....as what you said?
                                [QUOTE=r035198x] All I can say is an ArrayList can contain other lists as elements as well.
                                Code:
                                 ArrayList list = new ArrayList(); 
                                list(0) = new ArrayList();
                                Coz, my aim here is to create many ArrayList (or list - not sure) with the same variable (ifs1) in loop.
                                again, not sure this is possible or not.....

                                Comment

                                Working...