2015年3月30日 星期一

[ Java 常見問題 ] Convert List of Bytes to array of bytes

Source From Here 
Question: 
Trying to solve what should be a simple problem. Got a list of Bytes, want to convert it at the end of a function to an array of bytes

How-To 
What you can do is use commons-lang's ArrayUtils.toPrimitive(wrapperCollection)
  1. Byte[] bytes = pdu.toArray(new Byte[pdu.size()]);  
  2. return ArrayUtils.toPrimitive(bytes);  
If you can't use commons-lang, simply loop through the array and fill another array of type byte[] with the values (they will be automatically unboxed)

沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...