Hesam
Hesam

Reputation: 53600

intellij idea, How to find package name from code?

In eclipse when you copy a code from Internet for example and paste into IDE, when you put mouse on top of method, Eclipse shows this method belongs to what package ans class. So, you can by one click add it to code.

I have copy/pase following code into IntelliJ IDE:

double d1, d2;
Scanner scannerObject = new Scanner(System.in);
d1 = scannerObject.nextDouble();
d2 = scannerObject.nextDouble();
System.out.println("You entered " + d1 + " and " + d2); 

My question is, is there a way like eclipse to add package and class name of Scanner into code instead of typing import java.util.Scanner; manually?

Upvotes: 0

Views: 1658

Answers (2)

jtonic
jtonic

Reputation: 639

There is also a useful preference "Settings>Editor>Auto Import>Optimize imports on the fly" you can switch on.

Regards

Upvotes: 2

Ilya
Ilya

Reputation: 29673

press alt + enter -> import class on class, and you will get list of possible packages

Upvotes: 2

Related Questions