I have a string of India districts. For example String districts = district1,district2,district3,...so on (maybe all or some of districts of India).
Assume,
district1,district2,district3 are Rajasthan's district
And
district4,district5,district6 are Gujrat's districts
What is scenario
I want to show districts variable in TextView but if this string contains all districts of any state(s) then only state name should be shown in place of all districts of it. It will reduce the size of string and will look much better.
For detailed explanation refer to base question
Achieved Case 1
Input = district1,district2,district3,district4
Output = Rajasthan,district4
Achieved Case 2
Input = district1,district2,district3,district4,district5
Output = Rajasthan,district4,district5
Achieved Case 2
Input = district1,district2,district3,district4,district5,district6
Output = Rajasthan,Gujrat
Above cases achieved by @Live and Let Live answer
Expected Case 1
Input = district1,district2,district3,district4
Output = Rajasthan, Gujrat (district4)
Expected Case 2
Input = district1,district2,district3,district4,district5
Output = Rajasthan,Gujrat (district4,district5)
Expected Case 3
Input = district1,district2,district3,district4,district5,district6
Output = Rajasthan,Gujrat