2012-09-13 85 views
3

我有3個布爾這表明,如果一個int應該被添加到列表或沒有,那麼我想這個名單上使用TextUtils.join()TextUtils.join整數ArrayList的

我應該如何進行?

ArrayList<Integer> types = new ArrayList<Integer>(); 

if (m_bWithA) { 
    types.add(this.TYPE_A); //TYPE_A is an int 
} 
if (m_bWithB) { 
    types.add(this.TYPE_B); 
} 
if (m_bWithC) { 
    types.add(this.TYPE_C); 
} 

TextUtils.join("|", types); 

但它說,我們只能Object[]使用TextUtils.join()

我應該使用其他功能或不同類型的對象?

+0

不是整數'ArrayList'一個'Iteratable',其通過'.join' [這裏]接受(http://tinyurl.com/ppmvlpc) – Sourabh

+0

同意Sourabh,。加入將與任何Iterable一起使用。如果你看看文檔,Iterable擴展了CharSequence,CharSequence擴展了我相信最原始的類型。我已經使用.join多次加入一個Integers的ArrayList。 – JamisonMan111

回答

5

使用TextUtils.join(types.toArray())

相關問題