How can I import multiple packages in one java file. For example if I created a main method in one java file and packages in different. I want to import 3 packages in one line then how can I import all in one line?
In Java, you can import entire package using *
. to import multiple packages. eg import com.package1.*;
to import everything from package1. To import multiple packages, eg import com.package1.*; import com.package2.*; import com.package3.*;
import com.package1.*; import com.package2.*; import com.package3.*;
Importing on a single line like import package1.*,package2.*,package3.*;
is not possible in java but you can import entire directory if the packages are in the same directory as in import com.*;
The wildcard *
can import everything from a single package:
import junit.*;
Just be sure you don't clutter your local namespace with classes you are not using. If you're using a Java IDE, consider using the Organize Imports feature (ctrl-shift-o in Eclipse) instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.