2

When I use String in Java do I need to import java.lang.String? Or I can simply use it?

Is String imported by default? I am using Eclipse and as I know they use another compiler that Java does. What is the standard way?

3
  • 1
    java.lang.* is automatically imported. stackoverflow.com/questions/2073680/… Commented Mar 12, 2014 at 19:36
  • you don't need to import java.lang.String Commented Mar 12, 2014 at 19:36
  • 1
    This question could have been easily avoided... Commented Mar 12, 2014 at 19:37

5 Answers 5

8

No, java.lang.* is imported by default.

Sign up to request clarification or add additional context in comments.

Comments

1

You don't need to import anything from java.lang. It is imported by default. Everything in there is available without a need to explicitly import anything.

Comments

1

You don't need to formally import java.lang.String .. would represent being "overly redundant" when reading code.

Comments

0

By default, Java classes import all java.lang classes. It's pretty rare to see Java code that explicitly imports java.lang.String.

Comments

0

No, it is imported. use :String [name] = "[value]";

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.