How to transform a text into numbers in the shortest way possible? My challenge is to transform a text into a representation of numbers 0-9. The number representation has to be as short as possible. What are the best options to achieve this?

Edit: I also need to transfer it back to text.
The best approach is to compress the text, then encode the output as decimal digits.

For the compression, the state of the art is complex; it was/is PAQ8 (used by the current holder of the Hutter Prize); PPM* is also quite good. In the realm of common, there's bzip2 and other methods based on the Burrows-Wheeler transform. In the realm of easily done, there's zlib, which is built in java.util.zip

Encoding the output in decimal is the easy part. A trivial method is to consider the bit string or octet string output by compression as an integer in a prescribed endianness, and convert that into decimal. The method is well known (basically: divide by 10, use the remainder as an output digit, and repeat dividing the quotient until that's 0). That's even built in Java's java.math.BigInteger (for big-endian). The only caveats are that with the big-endian convention, removing leading zeroes will be a disaster; the original length might be needed to allow decompression (depending on the compression method); and (with the standard algorithm outlined) execution time grows with the square of the size. If the later becomes a problem, one can subdivide the binary output into fixed-size blocks (except for an agreed-upon one, e.g. last), efficiently converted to a fixed size decimal output with a small size overhead. For example, 22 octets can be converted to 53 digits with less than 0.036% overhead, noticing that 25622 is just shy of 1053.

The reverse operation is trivial: convert from decimal digits to bitstring or octet string, then decompress. One caveat is that erroneous input might trigger strange bugs in the decompressor.

Note: The compression will make the output a lot shorter for real text, but in the worst case can cause a slight expansion (that can be limited to 1 bit). If the worst case size is what matters, remove compression.

Note: This is only tangentially on-topic, unless it is added encryption between compression and encoding as digits. In this case, the compression can have undesirable effect (like, ciphertext size leaking information on plaintext nature for one knowing plaintext length).