I want to find occurrence of each character in their increasing order.
For eg. for input  abcddec output should be  a1b1c1d1d2e1c2 , but my 
code is giving me output as  a1b1c2d2e1c2
what changes I should make?
package com.Java8;
public class Occurences {
    public static void main(String[] args) {
        String str = "abb";
        char[] arr = str.toCharArray();
        String result = "";
        for (int i = 0; i < arr.length; i++) {
            int count = 0;
            for (int j = 0; j < arr.length; j++) {
                if (arr[i] == arr[j]) {
                    count++;
                }
            }
            result = result + arr[i] + count;
        }
        System.out.println(result);
    }
}
 
     
     
     
     
     
    