Click here to Skip to main content
15,886,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
rollNumberStream has String eg PE11115,HI34565,Pe5567,Pe5137,pe4324,EE21258 and I need to count number of people in specified department(Passed in arguments as dept) case insensitive.

If pe is passed it should consider PE11115, Pe5137,pe4324 all of these

What I have tried:

public static int getCount(Stream<string> rollNumberStream, String dept) {

long count_roll=rollNumberStream.filter(x->x.startsWith(dept)).count();
int count=(int)count_roll;
return count;


}// this working fine with case sensitive but i want to ignore cases
Posted
Updated 15-Apr-21 23:59pm

Convert them both to lowercase before you compare them.
Convert the dept before you start comparing, and use toLower in your lambda to convert x before calling startsWith
 
Share this answer
 
String dept_lower=dept.toLowerCase();
long count_roll=rollNumberStream.filter(x->x.toLowerCase().startsWith(dept_lower)).count();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900