This is not a problem innate to cities, and it’s not even endemic within cities that have these problems.
Density still matters though. You can go your whole life in the middle of nowhere without seeing someone take a dump in a public place or see a car that's been broken into.
The problem in cities is usually that some people aren't allowed to use any of the many toilets that exist, which is a much easier problem to fix.