Skip to main content
Share Your Experience: Take the 2024 Developer Survey
22 votes

Tips for golfing in Java

Some small code-golfing tips These tips were a bit too small for a separated answers, so I will use this answer for very small codegolfing tips that I found or came up with, and aren't mentioned in ...
Kevin Cruijssen's user avatar
15 votes

Tips for golfing in Java

Convert String to number There are multiple ways to convert a String to an numeric value: String s = "12"; ABC.parseABC: ...
Kevin Cruijssen's user avatar
15 votes

Dollar Bill Auction

MimicBot ...
Nissa's user avatar
  • 3,624
11 votes

Tips for golfing in Java

Don't be afraid to use scientific notation If you are dealing with doubles, or floats, you can use scientific notation for numbers. So instead of writing ...
user902383's user avatar
  • 1,460
11 votes

Dollar Bill Auction

InsiderTradingBot In the spirit of @StephenLeppik's answer, InsiderTradingBot knows all of his opponents and understands their strategies. Your move, Stephen. ...
Silvio Mayolo's user avatar
10 votes

Battle of the Fellowships KotH

StaticCloud A sentient growing cloud which does static damage to anybody coming close. It consists of: 1/3 Invisible part STR: 5; AGI: 5; INT: 25 Clone, Invisible, Static 2/3 Visible part STR: 5; ...
Sleafar's user avatar
  • 2,912
9 votes

Tips for golfing in Java

Use Java 10's var If you define a single variable of a specific type, use var. Examples ...
Olivier Grégoire's user avatar
8 votes

Dollar Bill Auction

MirrorBot Makes the enemy play against itself. ...
anna328p's user avatar
  • 6,376
8 votes

Dollar Bill Auction

Edit: Targeted changes in the DollarBidder class has broken this bot. ScoreOverflowBot ...
Winter's user avatar
  • 209
7 votes

Battle of the Fellowships KotH

Template Player Uses Ranged, Flexible, Zap, and KO. You have permission to use this ability set if you wish. Feel free to use this bot as a template for creating your own. Remember that you need to ...
Nathan Merrill's user avatar
7 votes

Tips for golfing in Java

Shortest full program templates. Introduction The Java spec never ever say that a full program must contain a main method. It only says: The Java Virtual ...
Olivier Grégoire's user avatar
7 votes

Tips for golfing in Java

Use new Stack() when you need basic List functionality When you need a java.util.List (for ...
Kevin Cruijssen's user avatar
7 votes

Tips for golfing in Java

Avoid StringBuilders Appending stuff to a String takes up much fewer bytes. ...
SE is dead's user avatar
  • 1,382
7 votes

Battle of the Fellowships KotH

CowardlySniperMk2 Uses Zap, FarSight *2, and Hide. This bot is a coward. Its highest priority is not to be targeted. To that end he uses its superior sight to see where enemies are. It uses this ...
Moogie's user avatar
  • 1,720
7 votes

Battle of the Fellowships KotH

RogueSquad A rogue squad consists of: 1 Scout (stays in shadows while exploring the map) STR: 5; AGI: 5; INT: 25 Clone, Invisible, Far sight 2 Assasins (attack enemies with deadly poison) STR: 5; ...
Sleafar's user avatar
  • 2,912
7 votes

Battle of the Fellowships KotH

TheWalkingDead Zombies, everyone knows them. They stay in a group doing nothing until someone shows up. They are hard to kill, and no matter how many you kill there are always more. And they usually ...
Sleafar's user avatar
  • 2,912
7 votes

Shortest program to throw NullPointerException in Java

Java 8 - 56 53 bytes (11 byte snippet) interface P{static void main(String[]a){throw null;}} ideone From the documentation: Class NullPointerException ... Thrown ...
Jonathan Allan's user avatar
7 votes

Dollar Bill Auction

MarginalBot ...
Qaghan's user avatar
  • 71
6 votes

Tips for golfing in Java

When you have a method that should return a boolean or Boolean, i.e.: ...
Kevin Cruijssen's user avatar
6 votes

Tips for golfing in Java

How to Draw in Java... Here's the shortest possible GUI paint boiler-plate: ...
Magic Octopus Urn's user avatar
6 votes

Battle of the Fellowships KotH

Bear Cavalry Uses Absorb, Clone and Bear; stats are (+9, +0, +11). On the first turn, everyone creates a clone of themselves, so that the team has 6 characters on the field. Then they charge the ...
Zgarb's user avatar
  • 42.7k
6 votes

Battle of the Fellowships KotH

Vampire I'm new to this and I'm not sure I know what I'm doing, but I thought it seemed interesting, so here is my attempt. The vampires will search for enemies and target the weakest, draining the ...
Herohtar's user avatar
  • 241
6 votes

Dollar Bill Auction

BorkBorkBot ...
AdmBorkBork's user avatar
  • 43.4k
6 votes

Dollar Bill Auction

DeterrentBot ...
histocrat's user avatar
  • 22.2k
6 votes

Dollar Bill Auction

RandBot ...
Neil's user avatar
  • 171k
6 votes

King of The Holster (finished)

#1 - FriendlyNotFriendlyBot ...
loggeek's user avatar
  • 503
5 votes

Tips for golfing in Java

Using ... (varags) as parameter In some cases it's shorter to use a Java varargs as parameter instead of loose ones. For example: ...
Kevin Cruijssen's user avatar
5 votes

Tips for golfing in Java

In most cases, your program will be single-threaded, i.e it'll have only one thread running. You can exploit this fact by returning from the main method when you ...
SE is dead's user avatar
  • 1,382

Only top scored, non community-wiki answers of a minimum length are eligible