Why new String(bytes, enc).getBytes(enc) does not return the original byte array?
<p>I made the following "simulation":</p>

<pre><code>byte[] b = new byte[256];

for (int i = 0; i &lt; 256; i ++) {
    b[i] = (byte) (i - 128);
}
byte[] transformed = new String(b, "cp1251").getBytes("cp1251");

for (int i = 0; i &lt; b.length; i ++) {
    if (b[i] != transformed[i]) {
        System.out.println("Wrong : " + i);
    }
}
</code></pre>

<p>For <code>cp1251</code> this outputs only one wrong byte - at position 25.<br>
For <code>KOI8-R</code> - all fine.<br>
For <code>cp1252</code> - 4 or 5 differences.</p>

<p>What is the reason for this and how can this be overcome?</p>

<p>I know it is <em>wrong</em> to represent byte arrays as strings in whatever encoding, but it is a requirement of the protocol of a payment provider, so I don't have a choice.</p>

<p><strong>Update:</strong> representing it in <code>ISO-8859-1</code> works, and I'll use it for the <code>byte[]</code> part, and <code>cp1251</code> for the textual part, so the question remains only out of curiousity</p>
