程式扎記: [ Java 常見問題 ] Convert List of Bytes to array of bytes

標籤

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)

沒有留言:

張貼留言

網誌存檔

關於我自己

我的相片
Where there is a will, there is a way!