Solve by first creating an array of all digits
\n\nimport java.util.Arrays;\n\npublic class SmallestValueOfRearrangedNumber {\n\n    public static long smallestNumber(long num) {\n        boolean isPositive 
```\n\nimport java.util.Arrays;\n\npublic class SmallestValueOfRearrangedNumber {\n\n    public static long smallestNumber(long num) {\n        boolean isPositive = false;\n        if (num >= 0) {\n            isPositive = true;\n        } else {\n            num *= -1;\n        }\n\n        if (num == 0) {\n            return num;\n        }\n\n        int totalDigits = 0;\n        long divider = 1;\n\n        while (divider <= num) {\n            totalDigits++;\n            divider *= 10;\n        }\n\n        int[] digitsArray = new int[totalDigits];\n        divider /= 10;\n        int d = 0;\n        for (int i = 0; i < totalDigits; i++) {\n            d = (int) (num / divider);\n            num = num % divider;\n            divider /= 10;\n            digitsArray[i] = d;\n        }\n\n        Arrays.sort(digitsArray);\n\n        int numOfZeros = 0;\n        for (int i = 0; i < digitsArray.length; i++) {\n            if (digitsArray[i] == 0) {\n                numOfZeros++;\n            } else {\n                break;\n            }\n        }\n\n        long minimalNum = 0;\n        int firstNonZeroIndex = numOfZeros;\n\n        if (isPositive) {\n            minimalNum = digitsArray[firstNonZeroIndex];\n            while (numOfZeros > 0) {\n                minimalNum *= 10;\n                numOfZeros--;\n            }\n            int i = firstNonZeroIndex + 1;\n            while (i < digitsArray.length) {\n                minimalNum *= 10;\n                minimalNum += digitsArray[i];\n                i++;\n            }\n        } else {\n            int totalNonZeros = totalDigits - firstNonZeroIndex;\n\n            int i = totalDigits - 1;\n            while (i >= firstNonZeroIndex) {\n                minimalNum *= 10;\n                minimalNum += digitsArray[i];\n\n                i--;\n            }\n            i = firstNonZeroIndex - 1;\n            while (i >= 0) {\n                minimalNum *= 10;\n                i--;\n            }\n            minimalNum *= -1;\n        }\n\n        return minimalNum;\n    }\n\n    public static void main(String[] args) {\n        System.out.println(smallestNumber(310));\n        System.out.println(smallestNumber(-7605));\n        System.out.println(smallestNumber(70047658));\n        System.out.println(smallestNumber(-70047658));\n        System.out.println(smallestNumber(435));\n        System.out.println(smallestNumber(-435));\n        System.out.println(smallestNumber(43597802));\n        System.out.println(smallestNumber(-43597802));\n    }\n}\n\n```
['Array', 'Java']