[Java] Maintain a count Array
```\nclass Solution {\n    public static boolean check(int[] arr) {\n        for(int i = 0; i < 26; i++) if(arr[i] != 0) return true;\n        return false;\n  
```\nclass Solution {\n    public static boolean check(int[] arr) {\n        for(int i = 0; i < 26; i++) if(arr[i] != 0) return true;\n        return false;\n    }\n    public String sortString(String s) {\n        int n = s.length();\n        int[] arr = new int[26];\n        StringBuilder res = new StringBuilder();\n        for(int i = 0; i < n; i++) arr[s.charAt(i) - \'a\']++;\n        while(check(arr)) {\n            for(int i = 0; i < 26; i++) {\n                if(arr[i] > 0) {\n                    arr[i]--;\n                    res.append((char)(i + 97));\n                } \n            }\n            for(int i = 25; i > -1; i--) {\n                if(arr[i] > 0) {\n                    arr[i]--;\n                    res.append((char)(i + 97));\n                } \n            }\n        }\n        return res.toString();\n    }\n}
[]