Java IO Tutorial - Java Charset.canEncode()








Syntax

Charset.canEncode() has the following syntax.

public boolean canEncode()

Example

In the following code shows how to use Charset.canEncode() method.

import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.Map;
/*  w w  w  . j a  v a 2 s. c o m*/
public class Main {

  public static void main(String[] args) {
    Map<String, Charset> charsets = Charset.availableCharsets();
    Iterator<Charset> iterator = charsets.values().iterator();
    while (iterator.hasNext()) {
      Charset cs = (Charset) iterator.next();
      System.out.println(cs.displayName());
      System.out.println(cs.canEncode());
    }
  }
}

The code above generates the following result.