[英]Convert Arraylist<Object> value in to byte[]
我想在下面的byte []中獲取/轉換Arraylist的值是我的代碼
final ArrayList<Object> imglists = new ArrayList<Object>();
這是我在這個arraylist m中的對象的arraylist,以字節的形式存儲圖像的值
for (int i=0; i<mPlaylistVideos.size();i++) {
holder.mThumbnailImage.buildDrawingCache();
Bitmap bitmap= holder.mThumbnailImage.getDrawingCache();
ByteArrayOutputStream bs = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, bs);
byte[] rough = bs.toByteArray();
imglists.add(i,rough);
}
我試圖從arraylist獲取特定值並將其存儲在byte []中這就是我想要做的事情
byte[] value=imglists.get(2);
我找不到將Object的Arraylist轉換為byte []的完整答案我知道Arraylist不支持原始數據類型(即byte)
您想將ArrayList轉換為byte []嗎? 或者對象為byte []?
我用這種方式編寫,只需將ArrayList中的元素轉換為byte [],就可以了!
List<Object> objects = new ArrayList<Object>();
objects.add("HelloWorld".getBytes());
byte[] bytes = (byte[]) objects.get(0);
System.out.println(new String(bytes)); // HelloWorld
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.