Wednesday, May 11, 2016

[Java] Parsing Char String Integer Double

char / Character

        char c = '5';

                To Integer

      1. Character.getNumericValue(c)
      2. int i = c - '0';                

                To Double

      1. double d = (double) (c - '0');

        Character c = '5';

    1. Convert to char using c.charValue(); 


Double  / double

        double d = 1.0;
        Double D = 1.0;

        To Integer

    1.  Integer i = D.intValue();
    2.  int i = (int)d;

int / Integer

        To Char

                Integer.toString(i).charAt(0)

        Generate char according to it's index

                (char)('A' + i)
                (char)('a' + i)
                 'A' + i and 'a' + i in java are ascii integers, need (char) to convert back to char.

        To String

                Integer.toString(i);

String

        String s1 = '500';

        String s2 = "5.0".

                To Integer

      1. Integer.parseInt(s1);  

                To Double

      1. Double.praseDouble(s2);

No comments:

Post a Comment