Q:

How to replace the n th occurance of a character in a String ?

I need to replace all commas after the 5th one. So if a String contains 10 commans, I want to leave only the first 5, and remove all subsequent commas. 
How can I do this ?  
String sentence = "Test,test,test,test,test,test,test,test"; 
String newSentence = sentence.replaceAll(",[6]",""); 

A:

Just capture all the characters from the start upto the 5th comma and match all the remaining commas using the alternation operator |. So , after | should match all the remaining commas. By replacing all the matched chars with $1 will give you the desired output.
sentence.replaceAll("^((?:[^,]*,){5})|,", "$1");

DEMO

