java.util.List

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shana07
    Contributor
    • Jan 2007
    • 280

    #16
    Yes, you're right bro. I noticed it when I tried to track the 'equals' method and it refers to 'equals (Object o)' in java default class. until I changed my code to
    Code:
     Entry e = new Entry(14, true );       
           if(e.equals(new Entry(14, true)))
    but it's not practical work.

    Yes I put your code & it works fine. Also I can choose any entry to compare with. thanks.....

    Comment

    • shana07
      Contributor
      • Jan 2007
      • 280

      #17
      Good Day!
      Again, allow me to ask further questions here regarding java.util.List.

      1. How if I use an Array rather than List - advantage of using List is?
      2 Could anyone gives me some pointers on how to convert List to an Array?
      the codes shown above are the one which need to be converted to array.

      Teach me on how to get array IF[] to store such information (exactly like what is done in the List above):
      Code:
      IF[0].position = 
      IF[0].value    = 
      IF[1].position = 
      IF[1].value    = 
      ...
      IF[n].position = 
      IF[n].value    = 
      
      if (n<0) 
      {
         Print "There is no if bytecode."}
      print n;
      Thank you..........

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #18
        Originally posted by shana07
        Good Day!
        Again, allow me to ask further questions here regarding java.util.List.

        1. How if I use an Array rather than List - advantage of using List is?
        2 Could anyone gives me some pointers on how to convert List to an Array?
        the codes shown above are the one which need to be converted to array.

        Teach me on how to get array IF[] to store such information (exactly like what is done in the List above):
        Code:
        IF[0].position = 
        IF[0].value = 
        IF[1].position = 
        IF[1].value = 
        ...
        IF[n].position = 
        IF[n].value = 
         
        if (n<0) 
        {
        Print "There is no if bytecode."}
        print n;
        Thank you..........
        You should really be reading the docs for this. You will find the toArray() method there as well.

        Comment

        • shana07
          Contributor
          • Jan 2007
          • 280

          #19
          By putting this code, I managed to get them in an array!
          Code:
          Object IF[] = ifs.toArray(new Object[ifs.size()]) ;
          Thanks to you.....
          Shana

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #20
            Originally posted by shana07
            By putting this code, I managed to get them in an array!

            Code:
            Object IF[] = ifs.toArray(new Object[ifs.size()]) ;
            Thanks to you.....

            Shana


            And thanks to the docs too of course.

            Comment

            • shana07
              Contributor
              • Jan 2007
              • 280

              #21
              Hi Friends, Sorry because I have one more question regarding this topic ;)
              I have 2 lists & initialized as:
              Code:
              java.util.List ifs = new java.util.ArrayList();
              java.util.List ifs1 = new java.util.ArrayList();
              In one method, I convert them to array with variables:
              Code:
              Object IF[] = ifs.toArray(new Object[ifs.size()]);
              Object IF1[] = ifs.toArray(new Object[ifs1.size()]);
              The first IF[] is main array and its length=4 (only one execution)
              IF1[] is supposed to execute in loop which each loop its length is also = 4.
              In short:
              Array IF1[]:
              0 – legth=4
              1 – length=4
              2 – ..
              3 – ..
              4 – ..
              5 – ..

              My questions:
              1. How to make IF1[] running in loop?
              2. At last after store all arrays, I need to compare 'VALUE' field for each data of arrays IF1[] with IF[]. Teach me how to do this?
              Code below gives an idea on what's to compare IF[] & IF1[]
              (the code is wrong, its supposed to be array comparisons)
              Code:
              Entry myEnt = (Entry)ifs1.get(i);          
              if(myEnt.equals((Entry)ifs.get(i)))
               { 
                  System.out.println ("A" );       
               }
                  else 
                   {
                  System.out.println ("B" );                       
                    }
              Here is my Entry(): -
              Code:
              class Entry
              {
                 public Object position;
                 public boolean value;
              
                 public Entry(Object position, boolean value)
               {
                   this.position = position;
                   this.value    = value;    
                }
                 
                 public boolean equals(Entry e) 
                 { 
                   return value != e.value;
                 }
              }
              Please advise & many thanks

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #22
                Originally posted by shana07
                Hi Friends, Sorry because I have one more question regarding this topic ;)
                I have 2 lists & initialized as:
                Code:
                java.util.List ifs = new java.util.ArrayList();
                java.util.List ifs1 = new java.util.ArrayList();
                In one method, I convert them to array with variables:
                Code:
                Object IF[] = ifs.toArray(new Object[ifs.size()]);
                Object IF1[] = ifs.toArray(new Object[ifs1.size()]);
                The first IF[] is main array and its length=4 (only one execution)
                IF1[] is supposed to execute in loop which each loop its length is also = 4.
                In short:
                Array IF1[]:
                0 – legth=4
                1 – length=4
                2 – ..
                3 – ..
                4 – ..
                5 – ..

                My questions:
                1. How to make IF1[] running in loop?
                2. At last after store all arrays, I need to compare 'VALUE' field for each data of arrays IF1[] with IF[]. Teach me how to do this?
                Code below gives an idea on what's to compare IF[] & IF1[]
                (the code is wrong, its supposed to be array comparisons)
                Code:
                Entry myEnt = (Entry)ifs1.get(i); 
                if(myEnt.equals((Entry)ifs.get(i)))
                { 
                System.out.println ("A" ); 
                }
                else 
                {
                System.out.println ("B" ); 
                }
                Here is my Entry(): -
                Code:
                class Entry
                {
                public Object position;
                public boolean value;
                 
                public Entry(Object position, boolean value)
                {
                this.position = position;
                this.value = value; 
                }
                 
                public boolean equals(Entry e) 
                { 
                return value != e.value;
                }
                }
                Please advise & many thanks
                Code:
                 if(IF[i].equals(IF1[i]))

                Comment

                • shana07
                  Contributor
                  • Jan 2007
                  • 280

                  #23
                  Hi, I've tried & it seems not compare for the VALUE field. it's comparing whole arrays. correct me if i'm wrong. tq

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #24
                    Originally posted by shana07
                    Hi, I've tried & it seems not compare for the VALUE field. it's comparing whole arrays. correct me if i'm wrong. tq
                    You mean the Lists contain Arrays? So what do you want to compare?

                    Comment

                    • shana07
                      Contributor
                      • Jan 2007
                      • 280

                      #25
                      I was thinking about the need to initialize IF[].value in here?
                      Which previously you once told me to put equals() in order to compare only VALUE field in Entry class (List).
                      And now since I do need to use array, how to make this comparison possible.....

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #26
                        Originally posted by shana07
                        I was thinking about the need to initialize IF[].value in here?
                        Which previously you once told me to put equals() in order to compare only VALUE field in Entry class (List).
                        And now since I do need to use array, how to make this comparison possible.....
                        Ok let's get some things clear here.
                        IF and IF1 are arrays containing what?
                        Do they contain Entry objects or are they arrays containing other arrays inside them?

                        Comment

                        • shana07
                          Contributor
                          • Jan 2007
                          • 280

                          #27
                          Originally posted by r035198x
                          You mean the Lists contain Arrays? So what do you want to compare?
                          Pretty understand your confusion. my blunder!
                          1. I'm not sure either still need to use Lists in here.
                          2. What I want to compare is only 'value' field in those arrays like this.
                          Code:
                            public boolean equals(Entry e) 
                             { 
                               return value != e.value;
                             }
                          The Lists:
                          Code:
                          ifs.add(new Entry(position, value)); 
                           ifs1.add(new Entry(position, value));

                          Comment

                          • shana07
                            Contributor
                            • Jan 2007
                            • 280

                            #28
                            Originally posted by r035198x
                            Ok let's get some things clear here.
                            IF and IF1 are arrays containing what?
                            Do they contain Entry objects or are they arrays containing other arrays inside them?
                            IF & IF1 arrays suppose to contain Entry objects: Please check this code (only for IF) which I was thinking I already put them into Array :
                            Code:
                            IfInstruction iff = (IfInstruction) insn;
                             Object IF[] = ifs.toArray(new Object[ifs.size()]) ;
                              Object position = insn.getOffset();
                                         
                              boolean value = iff.getConditionValue();
                               value = ! value;
                             ifs.add(new Entry(position, value));
                               System.out.println("IF.position: " +position);
                             System.out.println("IF.value: " +value);
                            My aim is to put such this in array:
                            IF[0].position
                            IF[0].value
                            IF[1].position
                            .....
                            ....
                            IF[3].position
                            IF[3].value

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #29
                              Originally posted by shana07
                              Pretty understand your confusion. my blunder!
                              1. I'm not sure either still need to use Lists in here.
                              2. What I want to compare is only 'value' field in those arrays like this.
                              Code:
                               public boolean equals(Entry e) 
                              { 
                              return value != e.value;
                              }
                              The Lists:
                              Code:
                              ifs.add(new Entry(position, value)); 
                              ifs1.add(new Entry(position, value));
                              The code that adds Entries to the lists shows that the Arrays IF and IF1 contain Entry objects so comparing their entries with IF[i].equals(IF1[i]) actually compares entries using their values. Is that what you want?

                              Comment

                              • shana07
                                Contributor
                                • Jan 2007
                                • 280

                                #30
                                Originally posted by r035198x
                                The code that adds Entries to the lists shows that the Arrays IF and IF1 contain Entry objects so comparing their entries with IF[i].equals(IF1[i]) actually compares entries using their values. Is that what you want?
                                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

                                Comment

                                Working...