+ Start a Discussion
My OwnMy Own 

Reg: How To Identify a List Item is exist or not ?



 Hi All, 


How To Identify a List Item is exist or not  in a list?. Please don't suggest me Map/Set. 


 Thanks in Advance.

Imran MohammedImran Mohammed

For ex, you have an String List and you are searching for a value in it, lets say sfdc.

You have to iterate the list in order to find the value

Have a Boolean value that will determine whether the value existed in List or  not


Boolean flag = false;

for(String s: stringList)


if(s == 'sfdc')


flag = true;




if(flag == true)// The flag will be true only if the value you looked for exists in list


//your code



If you are just looking for a first occurence then you can add break statement inside the loop so that you no need to traverse till end of the list..... Just a small tip :)

My OwnMy Own



Guys hold on this. Finally  I have fixed this.  


Thanks to all for your help.  :smileyvery-happy: