4

我有一个包含以下数据的属性文件:

acqurierSystemAlias=CTC0,CTC1,CTC2,CTC3,CTC4,FEXCO,AMEX,DINERS

现在在主程序中:

String acqurierSA = "CTC1";
String[] acqurierSystemAlias = properties.getProperty("acqurierSystemAlias").split(",");

for(String xyz: acqurierSystemAlias){
    if(xyz.equalsIgnoreCase(acqurierSA)) {
        System.out.println("true");
    } else {
        System.out.println("false");
    }
}

这让我回来了: false, true, false, false,false

我的要求只是在属性文件中返回,否则返回true,我只想要一个值。目前它正在向我返回循环中的值。acqurierSAfalse

4

5 回答 5

6

您可以制作一个list表格Array,然后检查contains()

String[] acqurierSystemAlias = properties.getProperty("acqurierSystemAlias").split(",");

List<String> lList=Arrays.asList(acqurierSystemAlias);

boolean found=lList.contains(acqurierSA );
System.out.println(found);

无需遍历数组。

于 2012-07-19T09:10:01.690 回答
3

您可以使用专用变量来执行此操作:

boolean found = false;

for(String xyz: acqurierSystemAlias){
    if(xyz.equalsIgnoreCase(acqurierSA)){
        found = true;
        break;
    }
}
System.out.println(found);
于 2012-07-19T09:01:49.367 回答
1

也许你不需要分割财产

System.out.println(("," + properties.getProperty("acqurierSystemAlias") + ",").contains("," +acqurierSA+ "," ));
于 2012-07-19T09:10:12.347 回答
0

检查这个。

String acqurierSA = "CTC1";
String[] acqurierSystemAlias = properties.getProperty("acqurierSystemAlias").split(",");

List<String> strList = Arrays.asList(acqurierSystemAlias);
strList.contains(acqurierSA);
于 2012-07-19T09:11:56.047 回答
0
public String processMountCheck() {
        logger.info("Logging an INFO-about Directory exists or not.");
        processPropFile();
        String[] urls = prop.getProperty("URL").split(",");
        List<String> list = Arrays.asList(urls);
        String[] folder = prop.getProperty("DIRECTORY").split(",");
        List<String> folders = Arrays.asList(folder);
        for (int i = 0; i < folders.size(); i++) {
            String k = folders.get(i);
            File file = new File(k);
            if (file.isDirectory()) {
                logger.info("Connected to a Directory!"+folders.get(i));
                if (file.list().length > 0) {
                    logger.info("Directory is not empty!");
                } else {
                    logger.info("Directory is empty!");
                }
            } else {
                logger.error("Invalid Directory!");
                // System.out.println("This is not a directory");
            }
        }
        return null;
    }
于 2017-06-02T12:41:27.627 回答