DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

将队列转换为字符串


LinkedBlockingQueue inputQ = new LinkedBlockingQueue();

Byte[] destArr = inputQ.toArray( new Byte[0]);

byte [] resultArr = new byte [destArr. length ];

for ( int i = 0; i < resultArr. length ; i++) {

resultArr[i] = destArr[i].byteValue();

}

strRes = new String(resultArr);

转换过程是:队列==>Byte数组==>byte数组==>字符串。下面是应用了此一转换的完整的Result类实现。

/**

  • 通过字节队列创建一个新的返回结果实例

  • @param inputQ

  • 结果字节队列

  • @param cmdType

  • 命令返回类型

*/

public Result( final LinkedBlockingQueue inputQ, final int cmdType) {

cmdReturnType = cmdType;

Byte[] destArr = inputQ.toArray( new Byte[0]);

byte [] resultArr = new byte [destArr. length ];

for ( int i = 0; i < resultArr. length ; i ++) {

resultArr[ i ] = destArr[ i ].byteValue();

}

strRes = new String(resultArr);

}



Published

Aug 11, 2010

Last Updated

Aug 11, 2010

Category

Tech

Tags

  • 队列 3
  • Java 106
  • 字符串 2

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor