Java 属性中具有多个值的单个键

Java 属性中具有多个值的单个键,java,Java,我有一个包含以下数据的属性文件: acqurierSystemAlias=CTC0,CTC1,CTC2,CTC3,CTC4,FEXCO,AMEX,DINERS 现在在主程序中: String acqurierSA = "CTC1"; String[] acqurierSystemAlias = properties.getProperty("acqurierSystemAlias").split(","); for(String xyz: acqurierSystemAlias){

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

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
如果
acqurierSA
在propertyfile中,或者返回
false
,我只需要一个值。目前,它正在向我返回循环中的值。

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

boolean found = false;

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

您可以创建一个
列表
表单
数组
,然后使用
contains()

String[]acqurierSystemAlias=properties.getProperty(“acqurierSystemAlias”).split(“,”);
List-lList=Arrays.asList(acqurierSystemAlias);
boolean found=lList.contains(acquriesa);
System.out.println(已找到);

不需要遍历数组。

可能不需要拆分属性 只是

看看这个

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

List<String> strList = Arrays.asList(acqurierSystemAlias);
strList.contains(acqurierSA);
String acqurierSA=“CTC1”;
字符串[]acqurierSystemAlias=properties.getProperty(“acqurierSystemAlias”).split(“,”);
List strList=Arrays.asList(acqurierSystemAlias);
strList.contains(acqurierSA);
公共字符串processMountCheck(){
info(“记录有关目录的信息是否存在。”);
processPropFile();
字符串[]URL=prop.getProperty(“URL”).split(“,”);
List=Arrays.asList(URL);
String[]folder=prop.getProperty(“目录”).split(“,”);
列表文件夹=数组.asList(文件夹);
对于(int i=0;i0){
info(“目录不是空的!”);
}否则{
info(“目录为空!”);
}
}否则{
logger.error(“无效目录!”);
//System.out.println(“这不是目录”);
}
}
返回null;
}

属性字符串:
a,b,,c
并搜索
b,
-假阳性(不应该在列表中,因为它只包含
a
b
,(空),
c
)因此,有一个问题,如果您的值可能包含“,”,则不能按“,”分割,因为可能“a,b,,”c”表示“a”,“b”,“c”。如果您的值不包含“,”,则无法使用“b”进行搜索。您可以使用“
”、“
进行拆分,但不应使用包含它的字符串进行搜索。。。而且(在我看来)若你们这样做了,你们永远不会得到积极的结果。检查这个装载检查的答案,在属性文件中加载单个键和多个值的值
System.out.println(("," + properties.getProperty("acqurierSystemAlias") + ",").contains("," +acqurierSA+ "," ));
String acqurierSA = "CTC1";
String[] acqurierSystemAlias = properties.getProperty("acqurierSystemAlias").split(",");

List<String> strList = Arrays.asList(acqurierSystemAlias);
strList.contains(acqurierSA);
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;
    }