求助,很简单的。。。

hysywlz 2003-08-21 09:08:24
我初学Java
不知这句代码是什么意思?
String tmpstr=new String(b,0,0,b.length);
(b是字符数组)
我知道是定义tmpstr字符串,可是b,0,0,b.length是什么意思呢?
...全文
27 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jscsqb 2003-08-22
  • 打赏
  • 举报
回复
byte b[] = {'a','b','c'};
String tmpstr = new String(b,0,0,b.length);

这个时候tmpstr="abc";
zcjl 2003-08-22
  • 打赏
  • 举报
回复
呵呵
为什么关于技术方面的好文档都是e文的啊?
不过计算机方面的e文相对来说还算简单的了
只要耐心,大多数都能看懂
hysywlz 2003-08-22
  • 打赏
  • 举报
回复
头都看晕了
不过总算明白了
给分
zcjl 2003-08-21
  • 打赏
  • 举报
回复
使用例子如下:

public class GetASCII{
public static void main(String[] args){
byte b[] = {55,56,57,54,53};
String tmpstr = new String(b,0,0,b.length);
System.out.println(tmpstr);
}
}
zcjl 2003-08-21
  • 打赏
  • 举报
回复
String(byte[] ascii, int hibyte, int offset, int count)
Deprecated. This method does not properly convert bytes into characters. As of JDK 1.1, the preferred way to do this is via the String constructors that take a charset name or that use the platform's default charset.

应该是将一个byte数组转换为String吧
不过上面也说了,这是一个不推荐使用的api,因为This method does not properly convert bytes into characters
cuihao 2003-08-21
  • 打赏
  • 举报
回复
String
public String(byte[] bytes,
int offset,
int length,
String charsetName)
throws UnsupportedEncodingException
Constructs a new String by decoding the specified subarray of bytes using the specified charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the subarray.
The behavior of this constructor when the given bytes are not valid in the given charset is unspecified. The CharsetDecoder class should be used when more control over the decoding process is required.


Parameters:
bytes - the bytes to be decoded into characters
offset - the index of the first byte to decode
length - the number of bytes to decode
charsetName - the name of a supported charset
Throws:
UnsupportedEncodingException - if the named charset is not supported
IndexOutOfBoundsException - if the offset and length arguments index characters outside the bounds of the bytes array
NullPointerException - if charsetName is null
Since:
JDK1.1

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧