Code example for CharsetEncoder

Methods: encode

0
		CharsetEncoder encoder = charset.newEncoder();
 
		try { 
			// Convert a string to ISO-LATIN-1 bytes in a ByteBuffer 
			// The new ByteBuffer is ready to be read. 
			ByteBuffer bbuf = encoder.encode(CharBuffer.wrap("a string"));
 
			// Convert ISO-LATIN-1 bytes in a ByteBuffer to a character 
			// ByteBuffer and then to a string. 
			// The new ByteBuffer is ready to be read. 
			CharBuffer cbuf = decoder.decode(bbuf);
			String s = cbuf.toString();
		} catch (CharacterCodingException e) {
		} 
	} 
 
	private static void stringPool() { 
		String a = "foo"; 
		String b = "food".substring(0,3); 
		String c = b.intern();
		String d = "foodie".substring(0,3);