Remove the Arraylist

I have an ArrayList of selectitems called newRes2 and another an Arraylist of string called Nouvelleentree.
I want to remove the entry in the newRes2 based on Nouvelleentree.

for example, assume that Nouvelleentree has the string value 'a' and newRes2 also has selectitem with the value "a". To delete the entry.

I tried the same thing by creating "Value SelectItem Nouvelleentree", then the remove method.
"newRes2.remove (new SelectItem (newentry.get (i)));

But because the things are different and the result is false.

Can someone help me with this? Do I need to substitute in this case equals method?

Thank you.

If you want two SelectItems to be equal, you must override Equals () to reflect this.

However, another approach is to remove all of the SelectItems who a stringValue() contained in the Nouvelleentree collection.

for(iterator iter = newRes2.iterator(); iter.hasNext();)
  if (newentry.contains(iter.next().stringValue()) iter.remove();

Tags: Java

Similar Questions

  • remove the specific item in the arraylist

    Hey,.
    I just want to remove an element from a list of tables.

    private function addNewItem():void {
              object = new ObjectProxy();
              object.id = input.text;
              arrayList.addItem(object);
    }
    

    Now how can I remove the sound element identifying specific?

    something like this:

    arrayList.removeItem(object.id=="blabla");

    or

    for each (obj:Object in ArrayList){
              if(obj.id == "blabla"){
                   ArrayList.removeItem(obj.id);
              }
    }


    I hope you can help me.
    Greetings,
    Zombiecook

    Your second code example is close. Just remove the obj instead of the id when you find it like this:

    for each (obj:Object in list){          if(obj.id == "blabla"){               list.removeItem(obj);          }}
    

    Of course, it would be more efficient to simply do:

    for (var i:int = 0; i < list.length; i++){          if(obj.id == "blabla"){               list.removeItemAt(i);               break;          }}
    

    -Kevin

  • removing the objectoutputstream collection intake

    Hey guys, I have problems to remove a connection.

    How his installation:

    first of all I'm doing a chatclient where several users can enter and use for cat
    When the client is connected to chatserver

    an ArrayList is used to keep track off the coast of socket (objectoutputStream), so the Chatserver can write objects for them later.
    So what exactly happens, is when the server accepts the socket, I create objectoutputstream as shown below and add it to ObjectoutPutstream ArrayList, so objects can be written later to these customers. But the problem occurs when I disconnect one of the customers. Objecoutputstream ArrayList still has disconnected and related customer tries to write objects in client disconnected, which then results in an exception. I tried everything and can not find a way to remove the client disconnected from collection objectoutputstream.

    What I tried
    I tried to use sockets instead of objectoutputstream collection that is a socket becaouse has a connected called method that returns a Boolean value, it sends a null object to the client. weird, isn't it?

    ServerSocket serverScoket = new ServerSocket(5000);
    
    Socket clientSocket = serverSocket.accept();//accepting socket
    
    ObjectOutputStream stream = new ObjectOutputStream(clientSocket.getObjectOutputStream));
    
    objectoutputstreamList.add(stream);//adding stream to collection of objecoutputstream
    Code of IM client we help to debug
    package ChatClient;
    
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.net.Socket;
    import testingchat.UserInfo;
    
    
    public class ChatClient {
    
        ObjectOutputStream sendPacket = null;
        ObjectInputStream comingPacket = null;
        Socket clientSocket = null;
        UserInfo checkingUserName = null;
    
        //connection details
        private int portNumber;
        private String serverIp;
        /**
         * Constructor
         */
        public ChatClient(){
        }
    
        /**
         * We contact the server and try send data through stream
         */
        public void makeConnection(){
            try{
                clientSocket = new Socket(serverIp,portNumber);
                sendPacket = new ObjectOutputStream(clientSocket.getOutputStream());
                comingPacket = new ObjectInputStream(clientSocket.getInputStream());
    
                Thread newThread = new Thread(new PacketReader());
                newThread.start();
                System.out.println("networking established");
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    
    
        /**
         * Sending packet to the server
         */
        public void sendPacket(UserInfo userPacket){
            try {
    
                sendPacket.writeObject(userPacket);
                System.out.println(userPacket.getUserName());
            } catch (IOException ex) {
            }
        }
    
        public class PacketReader implements Runnable{
             public void run() {
                try {
                    UserInfo user;
                    while((user = (UserInfo) comingPacket.readObject()) != null){
                        checkingUserName = user;
                        System.out.println(checkingUserName.getUserName()+" inside emthod packetReader");
                    }
                } catch (Exception ex) {
                }
            }
        }
    
        /**
         * @param setting up portNum
         */
        public void setPortNum(int portNum){
            portNumber = portNum;
        }
    
        /**
         * @param setting up serverIp
         */
        public void setServerIp(String serverIp){
            this.serverIp = serverIp;
        }
    
        /**
         * Sending messages to user client user interface
         */
        public UserInfo sendUserInfo(){
            return checkingUserName;
        }
    
        /**
         * Checking UserName Valid
         */
        public boolean checkValidName(){
            System.out.println(checkingUserName);
           return checkingUserName.isUserValid();
        }
    
        
    }
    Code for chatserver
    package testingchat;
    
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.io.OutputStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    import java.util.ArrayList;
    import java.util.Iterator;
    
    /**
     *
     *
     */
    public class ChatServer {
        //To write objects to client
        private ArrayList<ObjectOutputStream> streamList;
        private ArrayList<UserInfo> totalUsers;
        /**
         * Constructor
         */
        public ChatServer(){
        }
    
        /**
         * making contact with client
         */
        public void makeConnection(){
            try {
                streamList = new ArrayList<ObjectOutputStream>();
                ServerSocket serversocket = new ServerSocket(5000);
                System.out.println("connecting to client......");
                while (true){
                    Socket client = serversocket.accept();
                    System.out.println("made a connection");
    
                    ObjectOutputStream stream = new ObjectOutputStream(client.getOutputStream());
                    streamList.add(stream);
    
                    Thread newThread = new Thread(new ClientHandler(client));
                    newThread.start();
                }
            } catch (IOException ex) {
            }
        }
        
        public static void main(String[] args){
            new ChatServer().makeConnection();
        }
    
        public class ClientHandler implements Runnable{
            Socket clienti = null;
            ObjectInputStream stream = null;
            public ClientHandler(Socket sock){
                totalUsers = new ArrayList<UserInfo>();
                clienti = sock;
                try{
                    stream = new ObjectInputStream(clienti.getInputStream());
                } catch(Exception e){
                }
            }
            public void run(){
                try {
                UserInfo userinfo = (UserInfo) stream.readObject();
                totalUsers.add(userinfo);
                if(userinfo.isCheckingForValidName()){
                    System.out.println(userinfo.getUserName()+"inside chatserver line 66");
                    confirmUserName(userinfo);
                }else if(userinfo.isUserValid()){
                         sendToClient(userinfo);
                }
            } catch (Exception e){
                e.printStackTrace();
            }
            }
    
            public void sendToClient(UserInfo user){
                Iterator it = streamList.iterator();
                while (it.hasNext()){
                try {
                    ObjectOutputStream objectWriter =  (ObjectOutputStream) it.next();
                    objectWriter.writeObject(user);
                    objectWriter.flush();
                } catch (Exception ex) { ex.printStackTrace(); }
            }
            }
    
            /**
             * Informs the login client whether any user with a incoming name is
             *
             */
            public void confirmUserName(UserInfo oCheckUser) {
                try {
                    for (UserInfo users : totalUsers) {
                        if (oCheckUser.getUserName().equals(users.getUserName())) {
                            oCheckUser.setUserValid(false);
                        } else {
                            oCheckUser.setUserValid(true);
                            oCheckUser.setCheckingForValidName(false);
                        }
                        //writing objects to client
                        for (ObjectOutputStream outGoing : streamList) {
    
                            outGoing.writeObject(oCheckUser);
                            outGoing.flush();
                        }
                        break;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
    
            }
        }
    }
    userInfo class, is the client object that sends to the server and server sends to clients deferential
    package testingchat;
    import testingchat.*;
    import java.io.Serializable;
    /**
     *
     * 
     */
    public class UserInfo implements Serializable{
    
        private String userName;
        private String message;
        private boolean checkingUserName;
        private boolean isUserValid;
    
        /**
         * Constructor
         */
        public UserInfo(){
            checkingUserName = true;
            isUserValid = false;
        }
    
        /**
         * Sending message to users
         * @param sMessage
         */
        public void sendMessage(String sMessage){
            message = sMessage;
        }
    
        /**
         * setting up user's Name
         * @param userName
         */
        public void setUser(String userName){
            this.userName = userName;
        }
    
        /**
         * @return message
         */
        public String getMessage(){
            return message;
        }
    
        /**
         * @return userName
         */
        public String getUserName(){
            return userName;
        }
    
        /**
         * @param oCheckingName
         */
        public void setCheckingForValidName(boolean oCheckingName){
            checkingUserName = oCheckingName;
        }
    
        /**
         * @return checkingUserName
         */
        public boolean isCheckingForValidName(){
            return checkingUserName;
        }
    
        /**
         * @param userValid
         */
        public void setUserValid(boolean userValid){
            isUserValid = userValid;
        }
    
        /**
         * @return isUserValid
         */
        public boolean isUserValid(){
           return isUserValid;
        }
    
    }
    Bravo guys, some help would be really appreciated

    The title of your son and the question that you ask, is how to remove something from a collection. I responded to it, not that it be answered if you read the Javadoc.

    What you want to know but have never actually asked is when* to remove from the collection. The answer is when you read EOS or get an IOException reading or writing of the connection.

    You will find that when you express yourself clearly, you will get clear answers. You will also write better code...

  • removed the audio tracks in logic pro can be restored

    removed the audio tracks in logic pro can be restored, has been save logic & empty folders to the folder came, I deleted the originals by mistake...

    Not if you don't have the original audio files on your hard drive.  If you have deleted original, your only hope he then restore from a backup of your system, you have a.

  • How can I download apps using iOS iPhone 5 s 10 and a waterproof case (without removing the case each time!)

    I have an iPhone 5 s protected by a waterproof case, secure screw using Allen.

    This command removes the possibility of using the ID of the contact.

    Contact ID is required by the App Store!

    I found a way around locking the screen, but not found how to circumvent App Store

    Have you disabled the following: settings > Touch ID & password > iTunes and App Store?

  • How can I delete an email from apple mail after removing the content (by virus scan software?)

    Recently, I received an avalanche of emails with malicious attachments.  I have not opened any of the accessories, and my antivirus software has picked up malicious content and removed from the email.  Thus, I find myself with an email on my system, no content.  Unfortunately, the system does not allow me to then remove the (s) e-mail that is left.  How can I remove these 'empty' emails in my Inbox mailbox?

    ... my antivirus software has picked up malicious content and removed from the email.

    Allowing something to edit the database of e-mail will result by it becomes corrupted.

    If you use Time Machine, restore the email by "entering Time Machine" of in Mail and choose a time to restore. Then, just delete suspicious e-mails in the usual way. Exit full screen before entering Time Machine.

    You may not use software "anti-virus" not Apple on a Mac, for this reason and many others. Identify the product you use to get the uninstall instructions.

  • Remove the entries in the playlist.

    I can't get rid of unwanted entries in the playlist.  There is no x in the top right and the items won't slide.  I'm on Yosemite 10.10.5

    Highlight the item in the playlist column.  Hold down the CTRL key.  Click on the item and options pop up.  Select remove the element.  Yes I know.  Why they have just under the X in the corner?

  • You can remove the gaps between songs in itunes 12.5.1.21

    How can I remove the gaps between songs itunes 12.5.1.21

    Unfortunately, user control in playback gapless disappeared several years ago.  There are different things you can try. You can use a different ripper to rip tracks omitting gaps (see XLD).  You can set crossfade overlap packed during the silence between tracks.

  • Change the orientation of the mouse. Click the apple icon, and then select check box on the left. However, this box is covered by a video on the use of the mouse. How to remove the video?

    Change the orientation of the mouse.  Click the apple icon. System Preferences; OK to this point; the area to select 'Left hand' is covered by a video on the use of mouse clicks. How can I remove the video (s) so I can't select 'Left hand' in the box?

    System Preferences > mouse, and then select the tab more moves.

    Then on the left, select: slide between pages

    Click scroll left or right with one finger , and then make your choice.

    You cannot delete the video. This is a demonstration.

  • Under settings &gt; how to remove the storage data

    I went into settings > storage & use iCloud and I want to know how to delete data. For example in my mail application my iPad tells me that there are 796 MB. I emptied my Inbox, trash and sent the messages. Why is there so much use? In iMovie, I show 621 MB, that I do not use iMovie. How can I delete cache in my ios device?

    The simplest thing to try is a reset.  Press and hold the power and home together for 10 seconds until the Apple logo appears.

    That may well help your storage numbers.  If this is not the case, try a restore or remove the email account and reintroduce.

    Restore your iPhone, iPad or iPod touch from a backup - Apple Support

  • How to remove the curtain of the screen when the watch is not matched

    How can I remove the curtain of a unmatched watch screen?

    Follow the instructions in this discussion > How to disable screen curtain when iWatch not more paired with iPhone?

  • Remove the old Apple ID

    My App Store won't let me update my applications... He said: I need my old Apple ID and I have not used this ID in a long time... And I made a new Apple ID a few months ago... And my App Store is the only thing that gives me problems... I do not know my old password Apple ID... I used an email from friends... And I no longer communicate with them and I have no way to get the password... And I would like to delete the old account app ID... So, I can continue to use my other... Please and thank you...

    Remove the apps and download/purchase once again using your ID

  • Need to change or remove the user name?

    Hello

    I have created a username of support or forum for the community and was signed to automatically by using the ID of the evil of apple.  Remove the current user name?  If I change it very well, but deletion is also an option if I can create a new one.  None where the Web page asked me for the apple ID.  Just sign me somehow.

    Hello

    I noted your request to the Apple moderators.

    It may be a day or two before they can help. Be patient.

  • My Apple Watch asked the password whenever I raise my hand.  He normally only for this, after I removed the watch and put it back on.

    My watch ask me the password whenever I raise my hand to look at. He normally doesn't do that when I removed the watch for charging.  I haven't changed anything so I don't know what causes this problem.  Help, please!

    Hello

    The following steps may help:

    • Make sure detection of wrist is still open:
      • On your iPhone, in the application of the watch, go to: Watch My > General > detection of wrist - turn on.
    • Make sure you wear your watch sufficiently snug on top of your wrist (if it is worn too loosely, your watch may believe that he had been removed from your wrist).
  • How can I remove the tones created in garageband that have been uninstalled? I also installed but I can't remove it either please help thanks

    How can I remove the tones created in garageband that have been uninstalled? I also installed but I can't remove it either please help thanks

    Hello Michael,

    Welcome to Apple Support communities.

    I see that you need assistance, removal of GarageBand ringtones that were uninstalled. I know it's nice to be able to properly manage your tones. I can help you with this.

    Use the article for iOS (iPad) 2.0.x GarageBand: GarageBand share songs, more precisely, this section:

    To remove the existing ringtones follow these steps:

    • Press to select, then press the button Delete for any ringtone you want to delete.

    • Drag a ringtone in the list, and then press delete.

    Have a great day!

Maybe you are looking for