I heard in Food Factory on Discovery Channel that roasted cashew nuts' cans are filled with nitrogen gas instead of oxygen to prevent growth of bacteria; but I thought oxygen is toxic for most kinds of bacteria. How come?
While oxygen is indeed toxic to many bacteria, namely obligate anaerobes, not all bacteria are obligate anaerobes. There are many bacteria that are inobligate anaerobes, which means that they fare best in anaerobic (oxygen-free) environments, but can survive an aerobic environment. There are bacteria that are inobligate aerobes: they can survive in anaerobic environments but fare best in aerobic environments. There are even bacteria that are obligate aerobes, they need oxygen in the environment to survive. Cashews are vulnerable to a species of bacteria that is an obligate aerobe, so putting oxygen into the cans would be counterproductive it would encourage bacterial growth. However nitrogen would keep the environment anaerobic until the package is opened and thus kill obligate aerobic bacteria.