The suspect has 11 prior arrests, including weapon and drug possession, police said.
Stanley Williams was arrested on charges of attempted murder and was being held Monday. It wasn't clear if he had an attorney.
Police say they are looking for another suspect.
The little boy, Isaiah Rivera, was caught in the middle of a shootout around 4 p.m. Sunday in the courtyard of the Roosevelt Houses in Bedford-Stuyvesant.
He was shot in the leg and is in stable condition at Kings County Hospital.
Williams was arrested shortly after the shooting after tips came in to police.