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?

Nissa
  • 4,636
  • 8
  • 29
  • 37
Alon
  • 2,919
  • 6
  • 27
  • 47

5 Answers5

8

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

Marco Acierno
  • 14,682
  • 8
  • 43
  • 53
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.

Martin Dinov
  • 8,757
  • 3
  • 29
  • 41
1

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

ErstwhileIII
  • 4,829
  • 2
  • 23
  • 37
0

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

bcholmes
  • 944
  • 1
  • 9
  • 23
0

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

Nuclear_Man_D
  • 142
  • 11