function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC_DeveloperSFDC_Developer 

Store not null string variable value in another string

 
I have five string which contains some value I need to check if any of them contains value if yes then store them in Another string.

Currently I'm doing this like below:
List<string> slist = new List<string>();
String s1 = 'abc';
slist.add(s1);
string s2 = 'bcd';
slist.add(s2);
string s3 = 'cde';
slist.add(s3);
string s4 = 'def';
slist.add(s4);
string s5 = 'efg';
slist.add(s4);

string allstirng;
boolean check;
for(String s: slist){
    if(!check){
        allstirng +=',';
    }
    allstirng += s;
    check = false;
}

Is there any other better way of doing this.
 
Ajay K DubediAjay K Dubedi
Hello,
You can use like this :
for(String s: slist){
if(s==null && s==''){
allstirng +=',';
}else{
allstirng += s;
}
}
Thanks.