Surface analysis techniques are particularly important in the field of materials science, which help researchers to understand the mechanism behind complex chemical reactions and study the properties of different materials. Time-of-flight secondary ion mass spectrometry (ToF-SIMS), a highly sensitive surface analysis technique, allows the reliable determination of various materials. ToF-SIMS spectra of materials are usually enormously complex since typical raw data may include many peaks over large mass-to-charge ratio (m/z) ranges. Hence, the use of data-mining methods in processing ToF-SIMS data is becoming more popular and important. In this study we show that random forests model can be used to automatically classify several different lithium-containing materials and to extract representative peaks from ToF-SIMS spectra of these materials. Our study shows good performance in analyzing spectra of materials with similar and dissimilar compositions, which can provide researchers with the possibility of quick and automatic analysis of ToF-SIMS data.