-1

I had a cannot find symbol error when I used length() for a string inside a function and got rid of it when i used length. I need to know what is the reason for this?

code:

//this got cannot find symbol error
static int[] matchingStrings(String[] strings, String[] queries) {
        int n=queries.length();
        int ns=strings.length();
        int res[]=new int[n];
//this ran 
static int[] matchingStrings(String[] strings, String[] queries) {
        int n=queries.length;
        int ns=strings.length;
        int res[]=new int[n];
vishal N
  • 163
  • 10

1 Answers1

2

You are confused:

For array: array.length; For Strings: string.length();

For arrays, length is not considered a method, it is a constant (an attribute)(that's why there is no ()).

Ralph Aouad
  • 414
  • 4
  • 10