Here I've created two methods which are not
thread safe so I won't get counter 0 everytime as It should be. When I synchronize those methods yes I do get 0 everytime.
Output: Not 0 everytime, it varies.
My Question: Same way can anyone tell me how I should write an example of StringBuffer and StringBuilder so I can understand by getting results that StringBuffer is thread safe and StringBuilder is not.
I did for performance of both and found StringBuilder is bit faster than StringBuffer here is the code:
Output:Time Taken by StringBuffer is: 66 ms
Time Taken by StringBuilder is: 28 ms