Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Java List add duplicate the same object     - Linux kernel IPv6 protocol closed manner (Linux)

- Linux Network Programming - libnet Guide (Programming)

- Installation Yarock 1.1.4 Music Player in Ubuntu (Linux)

- MySQL completely uninstall and install Configuring Character Sets under Linux (Database)

- findmnt- Looking mounted file system (Linux)

- Linux install deploy Ansible (Linux)

- Ubuntu 15.04 and Ubuntu 14.04 installed Cinnamon 2.6 (Linux)

- Nine tips to protect the security of Linux desktop (Linux)

- Struts2 study notes -Valuestack (value stack) and OGNL expression (Programming)

- LNMP Note: Addressing mail function can not send mail (Server)

- Features and prevention methods elaborate network security grayware (Linux)

- Use 3G wireless network card under Linux (Linux)

- Ubuntu mysql stop fail to solve the problem (Database)

- Ubuntu Linux to create and increase the Swap partition tutorial (Linux)

- Hadoop 2.7.1 Installation and Configuration under RedHat Linux 6.5 (Server)

- When RHEL7 use fdisk partition, all partitions can not be used (Linux)

- Golang environment configuration recommendations (Linux)

- Nginx start, stop, smooth start, smooth upgrade (Server)

- Linux operating system boot process analysis (Linux)

- Install Debian Linux with R on the Android system (Linux)

  Java List add duplicate the same object
  Add Date : 2017-08-31      
  Java in List List add method does not check whether they contain items have been added

List added is a reference, and does not check whether the list has been added

This means: If you manage a bunch of cyclic object used to store the list of the operation should not be chained and should stack type, as otherwise the chain actually promote the availability of object will be to squeeze into garbage stack and then recovered off the list seems little change in size but in fact only a few references to actual objects, and any operations on the object (such as setting the visible property or set value) will be used to list incalculable Impact

And each added to the list, if the only requirement for the elements in the list of words (generally, right) to check whether already exists in the list.

By attaching the test code:

fucker b = new fucker ();
        fucker a = new fucker ();
        a.Oops ();
        b.Oops ();

        List < fucker> lbs = new ArrayList < > ();

        for (int i = 0; i < 10; i ++) {
            lbs.add (a);
            lbs.add (b);

        a.fuck ();
        for (int i = 0; i < 10; i ++) {
            lbs.get (0) .fuck ();
            lbs.remove (lbs.get (0));
            lbs.get (0) .fuck ();
            lbs.remove (lbs.get (0));


public class fucker {
    private int value = 0;

    public void fuck () {
        System.out.println ( "OOOO!");
        System.out.println (value);
        value = 0;

    public void Oops () {
        value = 1;
        System.out.println ( "Changed!");


In fact, such an object in general should not be managed, but the brothers do not trust java garbage collection, and I am sure he setVisible (View.Gone) view and think that method does not exist would be developed with a devastating obstacles, so a little compromise choice
- How common Linux automation tasks (Server)
- Spring loaded container finishes executing a method (Programming)
- MySQL separation Amoeba achieve literacy (Database)
- RedHat / CentOS ext4 partition can not be formatted large supplementary ext4 formatting (Linux)
- Findbugs installation documentation (Linux)
- Linux System Getting Started Learning: The Linux log (Linux)
- Ubuntu root user profiles (Programming)
- Linux-based Heartbeat high availability configuration httpd service (Server)
- Linux file system management partition, format, mount - label mount (Linux)
- Android components save state series - Activity (Programming)
- Linux how to handle file names that contain spaces and special characters (Linux)
- Linux iptables firewall settings (Linux)
- Linux ./configure --prefix command (Linux)
- Ubuntu buffalo wzr-hp-300nh brush DD-WRT router system (Linux)
- grub boot error resolution examples (Linux)
- The Java development environment to build under Ubuntu 14.04 (Linux)
- git checkout generated in the use of temporary br (Linux)
- ARM Linux system call (Linux)
- To create and manage virtual machines on Ubuntu Redhat (Linux)
- RMAN backup file is much larger than the size of the database Cause Analysis (Database)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.