Java maxchars方法_Java CharsetDecoder maxCharsPerByte()用法及代码示例

maxCharsPerByte()方法是java.nio.charset.CharsetDecoder类的内置方法,该方法返回为每个输入字节生成的最大字符数。该值可用于计算给定输入序列所需的输出缓冲区的最坏情况大小。

用法:

public final float maxCharsPerByte()

参数:该函数不接受任何参数。

返回值:该函数返回每个输入字节产生的最大字符数。

下面是上述功能的实现:

示例1:

// Java program to demonstrate

// the above function

import java.nio.charset.*;

import java.util.Iterator;

import java.util.Map;

public class GFG {

public static void main(String[] args)

{

// Gets the charset

Charset charset = Charset.forName("ISO-2022-CN");

// Get the CharsetDecoder

CharsetDecoder decoder = charset.newDecoder();

// Prints the maxCharsPerByte

System.out.println("The maxCharsPerByte for "

+ "ISO-2022-CN is "

+ decoder.maxCharsPerByte());

}

}

输出:

The maxCharsPerByte for ISO-2022-CN is 1.0

示例2:

// Java program to demonstrate

// the above function

import java.nio.charset.*;

import java.util.Iterator;

import java.util.Map;

public class GFG {

public static void main(String[] args)

{

// Gets the charset

Charset charset = Charset.forName("x-windows-949");

// Get the CharsetDecoder

CharsetDecoder decoder = charset.newDecoder();

// Prints the maxCharsPerByte

System.out.println("The maxCharsPerByte for "

+ "ISO-2022-CN is "

+ decoder.maxCharsPerByte());

}

}

输出:

The maxCharsPerByte for ISO-2022-CN is 1.0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值