my question is that i want to use Scanner object or Arrays object for example for usage of Arrays.copyof, but before importing java.util.* or java.util.Scanner and java.util.Arrays there is now object of them to use ! why this happens to me??enter image description here
Asked
Active
Viewed 1,619 times
-2
-
2Perhaps because `Scanner` and `Arrays` part of java.util ??? I'd recommend to read about imports in Java – Verv Oct 11 '17 at 14:36
-
1Possible duplicate of [How does Java import work?](https://stackoverflow.com/questions/12620369/how-does-java-import-work) – Brian J Oct 11 '17 at 15:28
1 Answers
0
It is a little unclear what you want to achieve. Are you asking why you should do imports in Java?
import
statements allow you to refer to classes which are declared in other packages without referring to their full package name. This is standard java practice. Inside your main(String args[]
you can use java.util.Scanner myobject = new ..
if you want, but that is too cumbersome and often you have multiple classes in a package that you want to use. So adding a simple import java.util.*
is considered better.
Another tip is to use one among the large number of available IDEs (eclipse, sublime, IntelliJ) which will add the imports automatically for you.

Max Arbiter
- 318
- 4
- 18
-
actually my question is why the IntelliJ IDE doesn`t import java.util.scanner automatically when i use for example:" Scanner newscanner=new Scanner(system.in) – Mostafa Khoshbash Oct 11 '17 at 15:45
-
@MostafaKhoshbash Did you try [this](https://stackoverflow.com/questions/33261533/java-util-scanner-is-not-importing-when-using-scanner) question? or simply pressing Ctrl+Alt+O – Max Arbiter Oct 11 '17 at 16:01
-
it doesnt work u know without importing java.util.Scanner when i type Scanner it will be undefined and in red type and also there is no suggestion java.util to automatically imported! – Mostafa Khoshbash Oct 11 '17 at 17:00