Q)...An arraylist of Strings is
given as input. The count of the String elements that are not of size input2
string is to be returned.
input1: {"aaa","bb","cccc","d"}
input2: "bb"
output: 3("bb"-length:2)
input1: {"aaa","bb","cccc","d"}
input2: "bb"
output: 3("bb"-length:2)
- package Set1;
- import java.util.*;
- public class ClassSet28 {
- public static int StringsNotOfGivenLength(List<String> l1,String s1){
- int n1=s1.length();
- int c=0;
- for(int i=0;i<l1.size();i++){
- int n2=l1.get(i).length();
- if(n1!=n2)
- c++;
- }
- return c;
- }
- public static void main(String[] args) {
- Scanner s=new Scanner(System.in);
- System.out.println("enter the no.of elements:");
- int n=s.nextInt();
- List<String> l1=new ArrayList<String>();
- for(int i=0;i<n;i++)
- l1.add(s.next());
- System.out.println("enter the input string:");
- String s1=s.next();
- System.out.println(StringsNotOfGivenLength(l1,s1));
- }
- }