Considering that group formation is key when developing activities in collaborative learning scenarios, this paper aims to propose a strategy based on a genetic algorithm approach for achieving optimal collaborative learning groups, considering the students’ personality traits as grouping criteria. A controlled experiment was designed with 238 students, quantifying their personality traits through the “big five inventory” (BFI), forming working groups and developing a collaborative activity in programming and related courses. The experiment results allowed validation, not only from a computational point of view evaluating the algorithm performance but also from a pedagogical point of view, confronting the results obtained by students applying the proposed approach with those obtained through other group formation strategies. The highlight of the study is that those groups whose formation was pre-established by the teachers through the proposed strategy have generally had a better collaborative performance than the groups with traditional formation, except in the case of heterogeneous formation, at the time of developing a collaborative activity. In addition, through the experiment, it was found that not considering criteria related to personality traits before the group formation generally led to lower results.