- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to import all classes in Java?
All the classes in a package can be imported using the import statement along with the character *. For example - All the classes in the package java.util can be imported using import java.util.*;
A program that demonstrates this in Java is given as follows:
Example
import java.util.*; public class Demo { public static void main(String args[]) { Stack stack = new Stack(); stack.push("Apple"); stack.push("Mango"); stack.push("Guava"); stack.push("Pear"); stack.push("Orange"); System.out.println("The stack elements are: " + stack); } }
Output
The stack elements are: [Apple, Mango, Guava, Pear, Orange]
Now let us understand the above program.
The import statement along with the character * is used to import all the classes of the java.util package. The Stack is created using the class Stack. Then Stack.push() method is used to add the elements to the stack. Finally the stack is displayed. A code snippet which demonstrates this is as follows:
Stack stack = new Stack(); stack.push("Apple"); stack.push("Mango"); stack.push("Guava"); stack.push("Pear"); stack.push("Orange"); System.out.println("The stack elements are: " + stack);
- Related Articles
- How to import classes from within another directory/package in Java?
- How to import java.lang.String class in Java?
- How to list all the classes, interfaces, and enums in JShell in Java 9?
- How to remove all CSS classes using jQuery?
- How to remove all CSS classes using jQuery?
- Pseudo-classes and all CSS Classes
- How to import external libraries in JShell in Java 9?
- How to use classes in other package in Java
- Demonstrate Static Import in Java
- How to skip certain classes in StackFrame in Java 9?
- Why Object class is the super class for all classes in Java?
- How to put two public classes in a Java package.
- Nested Classes in Java
- Abstract Classes in Java
- What is static import in Java?

Advertisements