In the future, man is convicted of being anti-social. Sentenced to share an apartment with another man, who turns out to the most obnoxious person ever. At the end, protagonist figures out that roommate is an android programmed with his own personality. I think 1970s. I used to think by William Tenn, but couldn't find it among Tenn's work. (Maybe it's there, though.)
That sounds like R26/5/PSY and I by Michael G Coney.
The man has been diagnosed with "chronic apathy" and the android (he knows it is an android from the start) is part of the treatment.
"You were found in your room by my men following a call from Central," he informed me, as if I didn't already know. "A spot-check on Central's switchboard revealed that your door hadn't been opened for two months. They found you sitting in a chair next to the food chute with the 3-V switched off. They diagnosed chronic apathy; correctly, I think, and they brought you here."
The treatment is experimental
"... I'm going to give you a companion for a while," he said surprisingly. "Someone to cheer you up. Snap you out of it. Much better than a Restraint Centre."
The robot arrives and irritates the protagonist instantly
"I am R26/5/PSY," he informed me explicitly. "I am your companion, and I trust we shall get on well together. Perhaps you will call me Bob, Mr. Johnson."
I didn't volunteer my Christian name; I wasn't having any bloody robot getting familiar with me. "Come in," I said, shortly and unpleasantly.
He obeyed and something in his attitude needled me, immediately.
And then he walked across the room and sat down in my chair.
And in the week that followed things went from bad to worse. I did however succeed in getting my chair back by the simple expedient of asking for it. After all, he had to obey direct commands. But he gave way with extreme bad grace and salved his pride by pacing the room in aggravating fashion before eventually switching on the the 3-V.
The treatment is successful
"How did you get on with your robot?" asked Ford, eyes twinkling from within the fatty tissue.
I was about to make some evasive reply, then realised that I couldn't fool this man."Badly," I said.
"Good," said Ford, "I suppose you guessed that was the general idea?"
"The robot possessed an almost perfect replica of your own brain!"
"For the past three weeks you've been living with yourself!"