encoding By ISO-8859-1 - Java java.lang

Java examples for java.lang:String Unicode

Description

encoding By ISO-8859-1

Demo Code

//package com.java2s;
import java.io.UnsupportedEncodingException;

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

    public static String encodingByISO8859_1(String string) {
        if ((string != null) && !("".equals(string))) {
            try {
                return new String(string.getBytes(), "ISO-8859-1");
            } catch (UnsupportedEncodingException e) {
                return string;
            }
        }
        return string;
    }
}

Related Tutorials