arrays - Will an arraylist be empty after adding the object to another arraylist -


public void enqueue(packet...packets) {      arraylist<packet>type1 = new arraylist();    arraylist<packet>type2 = new arraylist();    boolean t = true;      for(packet packet : packets)    {        if(packet.getclasstype() == t )        {            type1.add(packet);        }           else        {            type2.add(packet);        }            }       if(queue.isempty())    {        if(type1.isempty())        {        //do nothing        }        else        {        queue.addall(type1);        }        if(type2.isempty())        {        //do nothing        }        else        {        queue.addall(type2);          }    }     else    {         for(int = 1 ; i<=queue.size() ; i++ )        {            if (queue.get(i).getclasstype() != t)            {                if(type1.isempty())                {                    // nothing                }                else                {                queue.addall(i, type1);                }            }        }        if(type2.isempty())        {         // nothing        }        else        {        queue.addall(type2);        }    }  } 

in code arraylist of packets have classtype true or fase. in first stage, sort these packets based on classtype. after this, add these new arraylists (type 1 , type 2) in specific way arraylist 'queue'. wondering if, after code has been executed, arraylists type 1 , type 2 empty again, or should add function in code remove packets after have been stored in queue arraylist ?

kind regards

when add contents of arraylist arraylist, copying data first second. no, when not "emptying" content 1 list another. means original data still present in type1 , type2 arraylists, , present in new arraylist well. if want reuse type1 , type2 arraylists, easy way reinitialize them, overwrite reference new (empty) arraylist object. this...

type1 = new arraylist<>(); type2 = new arraylist<>(); 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -