
which package do i need to import to use length() method for strings. the compiler shows an error telling me that it can't find length() method..

You can find String class in java.lang.* package. It is a default package. There should not be any error if you are not importing its package.
class StringLength
{
public static void main(String[] args)
{
String st="Hello";
int len=st.length();
System.out.println("Length of string is: "+len);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.