Question: I want to convert any length of String to byte32 in Java.

Code

```
String s="9c46267273a4999031c1d0f7e40b2a59233ce59427c4b9678d6c3a4de49b6052e71f6325296c4bddf71ea9e00da4e88c4d4fcbf241859d6aeb41e1714a0e";

//Convert into byte32

```

Answer: 
From the comments it became clear that you want to reduce the storage space of that string to 32 bytes.

The given string can easily be compressed from the 124 bytes to 62 bytes by doing a hexadecimal conversion.

However, there is no algorithm and there will not be an algorithm that can compress any data to 32 bytes. Imagine that would be possible: it would have been implemented and you would be able to get ZIP files of just 32 bytes for any file you compress.

So, unfortunately, the answer is: it's not possible.
You can achieve with the following function

```
byte[] bytes = s.getBytes();

```