@SuppressWarnings("unchecked")
	private static final byte[] encodeList(ArrayList list) throws BencodingException
    {
        byte[][] list_segments = new byte[list.size()][];
        for(int i = 0; i < list_segments.length;i++)
        {
            list_segments[i] = encode(list.get(i));
        }
        int total_length = 2;
        for(int i = 0 ; i < list_segments.length; i++)
            total_length += list_segments[i].length;
        byte[] bencoded_list = new byte[total_length];
        bencoded_list[0] = 'l';
        bencoded_list[bencoded_list.length-1] = 'e';
        int offset = 1;
        for(int i = 0; i < list_segments.length; i++)
        {
            System.arraycopy(list_segments[i],0,bencoded_list,offset,list_segments[i].length);
            offset += list_segments[i].length;
        }
        return bencoded_list;
    }