Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i get the Unicode infinity symbol converted to String

I want to use the infinity symbol (8 lying sideways) in java.

furthermore i want to use it as a String component.
i did not find a working charcode/ascii code for this (is there any?).

i tried:

String s=Character.toString(236);
String s=Character.toString('236');

am i missing something?

i got this now:

System.out.println(Character.toString('\u221E'));

but the output is ?

i am using java 1.7 jdk and eclipse. why is the infinity sign not showing up?

like image 993
Wandang Avatar asked May 29 '12 21:05

Wandang


People also ask

How do you make an infinity symbol in text?

Infinity symbol text typing on keyboard. Hold the ALT key and type 236 on the num-lock keypad.

How do you make an infinity sign in Java?

We can also simply divide a number with zero to implement infinity in Java.


2 Answers

You need the Unicode infinity sign, U+221E. 236 is a Windows typing convention, that won't help you at all. '\u221e' is the character constant.

Now, I can't promise that this will result in any ∞ characters on your screen. That depends on what sort of computer you have, what font you are using, and what you set in -Dfile.encoding. Also see this question.

like image 141
bmargulies Avatar answered Oct 05 '22 21:10

bmargulies


I know this is very late reply but the below information will definitely help someone.

In Eclipse by default Text File encoding for console is Cp1252, then

How to support UTF-8 encoding in Eclipse

and I will encourage to handle the infinity symbol in String like below source:

String infinitySymbol = null;

try {

    infinitySymbol = new String(String.valueOf(Character.toString('\u221E')).getBytes("UTF-8"), "UTF-8");

} catch (UnsupportedEncodingException ex) {

    infinitySymbol = "?";
    //ex.printStackTrace(); //print the unsupported encoding exception.

} finally {

    System.out.print("Symbol of infinity is : " + infinitySymbol);

}
like image 27
ArifMustafa Avatar answered Oct 05 '22 21:10

ArifMustafa