# Do I need to use imports or can I call a class explicity?

New to code golf and tried finding an answer to this question but couldn't (surprisingly)

When scoring my golfed Java code I was told that I need to add in my imports as part of my score. My question is, if for example I am using a List. Do I need to use import java.util.* or (if it is only appearing once in my code anyway) use java.util.List<T> list = whatever; when I make the actual call which would obviously be shorter.

• You do not need import if you do java.util.List. Aug 16 '16 at 13:36
• Related (but not quite a dupe) Aug 16 '16 at 14:00

You don't need to use an import if you fully qualify the class, as you guessed and Leaky Nun said in comments. Usually it's shorter this way, unless you need to use a class multiple times.

This is included in Tips for golfing in Java, by the way, which is a recommended read if you haven't yet.

I don't know very much about java, but if

java.util.List<T> list = whatever


Is valid without the import, the you do not need to use

import java.util.*


In general, I would say only you need whatever it takes to make your program successfully compile/run. If you are using a function instead of a full program, you must include any necessary includes/imports so that you could copy and paste the entire submission into a full program, and it would successfully compile/run.

However, if there is another approach that allows you to avoid the wordy imports, by all means, use this shorter approach! As long as it is still valid java, remove any imports you want.