convert To UTF - Java java.lang

Java examples for java.lang:String UTF

Description

convert To UTF

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String s = "java2s.com";
        System.out.println(convertToUTF16(s));
    }/*from  www. j av a 2 s  . c  om*/

    public static String convertToUTF16(String s) {
        String out = null;
        try {
            out = new String(s.getBytes("UTF-8"), "UTF-16");
        } catch (java.io.UnsupportedEncodingException e) {
            return null;
        }
        return out;
    }
}

Related Tutorials