java - What is the time complexity of stream filter obtained from HashSet? -


set<integer> set = new hashset<>(); set.add(1); set.add(2); ... 

what time complexity of below operation? o(n) or o(1)?

set.stream().filter(e -> e == 1).findfirst(); 

you can understand better if see side, solution same :

for(integer : set){     if(i == 1){         break;     } } 

so o(n) because loop on set, , check 1 one, if condition correct return value else continue until n elsement


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -