20 runnable Java code examples.
Open any Java example to explore the code and run it online. No setup, no signup.Explore practical Java code examples with clear explanations. Open any example to edit and run it online — no setup, no signup.
Java
20How to convert a string to an int in JavaHow to iterate over a map in JavaHow to convert an array to a list in JavaHow to generate a random number in a range in JavaHow to check if an array contains a value in JavaHow to initialize a list in one line in JavaHow to declare and initialize an array in JavaHow to print an array in JavaHow to convert a string to an enum in JavaHow to break out of nested loops in JavaHow to split a string in JavaHow to sort a Map by value in JavaHow to read a file into a String in JavaHow to round to 2 decimal places in JavaHow to concatenate two lists in JavaHow to sort a list of objects by property in JavaHow to compare strings in JavaHow to join a list into a string in JavaHow to remove items from a list while iterating in JavaHow to get the current date and time in Java
Questions & answers
Java examples, explained
Can I run these Java code examples?
Yes. Open any Java example to edit and run its code on the CompileBytes engine without installing anything.
Is this free? Do I need an account?
Every example is free to read, run, edit, and copy. No account is required.
Can I copy these into my own projects?
Yes. These examples are designed to be copied and adapted to your own code.
Where can I run my own code?
Open the Java compiler from the main playground catalog, then paste or write any code you want to run.