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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With