Bookong
Bookong

Reputation: 13

A StringBuilder bug or not?

My test program is:

public class Test {
    public static void main(String[] args) {
        char ch = 65270;
        StringBuilder sb = new StringBuilder();
        sb.append(ch); 
        sb.append(" -> ");
        sb.append(Integer.valueOf(ch));
        System.out.println(sb.toString());
    }
}

Result is : 65270 <- ﻶ

I can not understand why ?

I expire result is : ? -> 65270

Actual result in terminal (use command "javac Test.java" and "java Test") : ? -> 65270

But in Eclipse console : 65270 <- ?

It looks like an Eclipse problem ?

Upvotes: 1

Views: 287

Answers (1)

Christian Hujer
Christian Hujer

Reputation: 17935

The reason for your result is that the character 65270 is an Arabic ligature. Arabic is a script that is written from right to left. The Eclipse console therefore changes the direction from left-to-right to right-to-left. If you try a character from a script that is not a right-to-left script, results will be as expected. Try 0x5678 which is the old Chinese symbol for ton (weight), for example.

Upvotes: 1

Related Questions