What causes a collapsed lung? Can this just happen out of the blue or are there specific behaviors or conditions that cause this?

A . A collapsed lung - also referred to as a pneumothorax in the medical literature - arises when the outer surface of the lung develops a "puncture" causing the lung to deflate. A pneumothorax can develop in certain medical conditions where the lungs are diseased and prone to developing a "puncture" --e.g. Asthma, cystic fibrosis, and emphysema and is more common in smokers. Sometimes a pneumothorax arises when there is no apparent underlying lung disease. This is referred to as a primary spontaneous pneumothorax and is typically seen in young, thin men. Sometimes having a family history of a collapsed lung can suggest a cause, and there are some rare inherited diseases such as marfan's syndrome in which a collapsed lung can occur out of the blue. Stopping smoking is the only specific behavior that will significantly reduce your chance of developing a collapsed lung.
Lots. It can happen spontaneously or underlying conditions include trauma, infection, cancer , copd.