Here are the groups of priests the sons of Aaron were separated into. The sons of Aaron were Nadab, Abihu, Eleazar and Ithamar.
But Nadab and Abihu died before their father did. They didn't have any sons. So Eleazar and Ithamar served as the priests.
With the help of Zadok and Ahimelech, David separated the priests into groups. Each group served in its appointed order and time. Zadok belonged to the family line of Eleazar. Ahimelech belonged to the family line of Ithamar.
More leaders were found among Eleazar's family line than among Ithamar's. So the priests were separated into their groups based on that fact. There were 16 family leaders from Eleazar's line. There were eight family leaders from Ithamar's line.
The priests were separated into their groups by using lots. That was the fair way to do it. The priests were officials of the temple and officials of God. They came from the family lines of Eleazar and Ithamar.
Shemaiah was a Levite. He was the son of Nethanel. He was the writer who recorded the names of the priests. He wrote them down in front of the king and the officials. The officials included the priest Zadok and Ahimelech. Ahimelech was the son of Abiathar. They also included the leaders of the families of the priests and the Levites. One family was chosen by lot from Eleazar. Then one was chosen from Ithamar.
The 1st lot that was drawn out was for Jehoiarib. The 2nd was for Jedaiah.
The 3rd was for Harim. The 4th was for Seorim.
The 5th was for Malkijah. The 6th was for Mijamin.
The 7th was for Hakkoz. The 8th was for Abijah.
The 9th was for Jeshua. The 10th was for Shecaniah.
The 11th was for Eliashib. The 12th was for Jakim.
The 13th was for Huppah. The 14th was for Jeshebeab.
The 15th was for Bilgah. The 16th was for Immer.
The 17th was for Hezir. The 18th was for Happizzez.
The 19th was for Pethahiah. The 20th was for Jehezkel.
The 21st was for Jakin. The 22nd was for Gamul.
The 23rd was for Delaiah. The 24th was for Maaziah.
That was their appointed order for serving when they entered the LORD's temple. That order was based on the rules Aaron had given them long ago. Everything was done exactly as the LORD had commanded Aaron. The LORD is the God of Israel.