1. The boy walked along the sidewalk in safety.

2. The boy walked along the sidewalk with safety.
--------------------------------
Are both grammatical?

in my opinion i think 2nd one is correct but the correct was to say it would have been something like " the boy walked along the sidewalk safely"

Both are fine, rfvv. "superman" has a third way of saying the same thing.

No, both sentences are not grammatically correct. The correct sentence is:

1. The boy walked along the sidewalk in safety.

The phrase "in safety" means that the boy was walking in a safe manner or without any danger. It is a proper phrase to express the idea that the boy was walking without any harm or risk.

On the other hand, the phrase "with safety" is incorrect in this context. The preposition "with" is used to indicate the means or instrument used to perform an action or to express accompanying circumstances. In this case, "safety" cannot be used as an instrument or means of walking along the sidewalk.

In summary, the first sentence is grammatically correct, while the second sentence is not.