具有多个属性值的单个键

时间:2012-07-19 08:59:04

标签: java

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

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");
    }
}

这回复给我:falsetruefalsefalsefalse

如果true在属性文件中,或者返回acqurierSA,我的要求就是返回false,我只需要一个值。目前它正在循环返回值。

5 个答案:

答案 0 :(得分:4)

您可以制作list表单Array,然后查看contains()

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

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

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

无需遍历数组。

答案 1 :(得分:3)

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

boolean found = false;

for(String xyz: acqurierSystemAlias){
    if(xyz.equalsIgnoreCase(acqurierSA)){
        found = true;
        break;
    }
}
System.out.println(found);

答案 2 :(得分:1)

也许你不需要分割财产 刚

System.out.println(("," + properties.getProperty("acqurierSystemAlias") + ",").contains("," +acqurierSA+ "," ));

答案 3 :(得分:0)

检查一下。

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

List<String> strList = Arrays.asList(acqurierSystemAlias);
strList.contains(acqurierSA);

答案 4 :(得分: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;
    }