A record 2,382,822 foreign nationals were registered as living in Japan as of the end of last year, a 6.7 percent increase from the previous year, the Justice Ministry said Friday.

The total includes 228,588 staying on trainee visas, up 18.7 percent and also a record high, and 277,331 on student visas, up 12.4 percent. Meanwhile, the number of foreign nationals illegally staying in the country stood at 65,270 as of Jan. 1, increasing for the third consecutive year.

By nationality, Chinese constituted the largest group of registered foreign residents at 695,522. South Koreans came second at 453,096, followed by Filipinos at 243,662.

Vietnamese jumped 36.1 percent to 199,990 due to a growing number of students and technical intern trainees, in what appears to be the result of Japanese companies increasingly investing in their country.

Among those illegally staying in Japan, 13,265 were from South Korea, 8,846 from China and 6,507 from Thailand, the ministry said. The number of Vietnamese also grew in the category, up 34.9 percent to 5,137, with some trainees believed to have stayed even after their resident status expired.