Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        9个月前关闭。
                    
                
        

我需要检查Currency.getAvailableCurrencies()是否包含
我的货币是一个字符串

我已经试过了

if(Currency.getAvailableCurrencies().contains("my currency")){
  // do something
}


但这会返回false,但其中包含"my currency"

最佳答案

Currency.getAvailableCurrencies()返回Set<Currency> doc,因此您尝试检查String始终返回SetCurrency对象的false中的Currency。您需要使用输入字符串创建Currency对象,使用Currency.getInstance获取实例

if(Currency.getAvailableCurrencies().contains(Currency.getInstance("my currency")))

09-10 03:22
查看更多