The direct formation of C-N and C-O bonds from inert gases is essential for chemical/biological processes and energy storage systems. However, its application to carbon nanomaterials for improved energy storage remains technologically challenging. A simple and very fast method to form C-N and C-O bonds in reduced graphene oxide (RGO) and carbon nanotubes (CNTs) by an ultrasonic chemical reaction is described. Electrodes of nitrogen- or oxygen-doped RGO (N-RGO or O-RGO, respectively) are fabricated via the fixation between N-2 or O-2 carrier gas molecules and ultrasonically activated RGO. The materials exhibit much higher capacitance after doping (133, 284, and 74 F g(-1) for O-RGO, N-RGO, and RGO, respectively). Furthermore, the doped 2D RGO and 1D CNT materials are prepared by layer-by-layer deposition using ultrasonic spray to form 3D porous electrodes. These electrodes demonstrate very high specific capacitances (62.8 mF cm(-2) and 621 F g(-1) at 10 mV s(-1) for N-RGO/N-CNT at 1:1, v/v), high cycling stability, and structural flexibility.