top of page
Search

Tip: Importing External Libraries in Java

Interested in using external classes and methods? Don't forget to import the necessary external libraries!


Let's use the ArrayList data structure as an example:

ArrayList<Integer> intRay = new ArrayList<>();

If you try to run a program using ArrayList, however, you will get an error. In order to use this data structure, you must import the ArrayList class to your file. The general format for importing external libraries is:

//import PACKAGE.NAME.CLASS;

Many of the most useful java classes are found in java.util (this would be the PACKAGE.NAME) . The CLASS in this instance would be ArrayList


So at the top of your file, include the code snippet:

import java.util.ArrayList;

If you want to import all classes of a package, use an asterix:

import java.util.*;

It's as simple as that!


Best,

Bronwyn




 
 
 

Recent Posts

See All
Java Switch Case

Ever needed to write a million if-else statements to the point where your brain is breaking and you're about an inch away from throwing...

 
 
 

Comments


bottom of page