Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import two classes from same java package in one statement

Tags:

java

Many times I'm writing my java code, import statements be like

import java.util.Scanner;
import java.util.ArrayList;

But when it is required to import more classes from java.util (or any other package), is there a way to import all the required classes in one line.

Like the code below

import java.util.Scanner,ArrayList;     OR
import java.util.{Scanner,ArrayList};

Anyhow the above two lines didn't work. Is there a way to do so ?

like image 692
Madhavareddy Vippala Avatar asked Jul 02 '26 14:07

Madhavareddy Vippala


1 Answers

Java language does not support that.

As far as importing top level classes is concerned, you have two options:

import package.path.ExactClass

or

import package.path.*

First one imports one and only one class, second one is wildcard import that imports all classes in that package.

like image 56
SadClown Avatar answered Jul 04 '26 02:07

SadClown



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!