Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single key with multiple values in property

Tags:

java

I having a property file containing below data :

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

now in the main program :

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

This is returning me : false, true, false, false, false

My requirement is just to return true if the acqurierSA is in the propertyfile or else return false, I want only a single value. Currently it is returning me the values in loop.

like image 608
Beginner Avatar asked Dec 27 '22 21:12

Beginner


2 Answers

You could make a list form Array and then check with contains()

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

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

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

No need to traverse through the array.

like image 115
amicngh Avatar answered Jan 06 '23 20:01

amicngh


You could use a dedicated variable to do this:

boolean found = false;

for(String xyz: acqurierSystemAlias){
    if(xyz.equalsIgnoreCase(acqurierSA)){
        found = true;
        break;
    }
}
System.out.println(found);
like image 20
assylias Avatar answered Jan 06 '23 20:01

assylias