DDileep OS
AboutProjectsJourneyBlogBooksContact
Available
--:--
DDileep OS

Building products, learning in public and becoming a better software engineer every day.

Available for opportunitiesv1.0.0

Explore

HomeAboutProjectsJourneyBlogContact

Resources

BooksLearningDSAJavaUsesResume

More

ExperienceAchievementsNowGuestbook

Connect

Follow my work, connect professionally, or drop me an email anytime.

© 2026 Dileep OS · Built with Next.js, Sanity and Tailwind CSS.

Developer toolkit — Java snippets

Write less.
Build faster.
Remember only what matters.

A curated collection of production-ready Java snippets that I use for interviews, DSA, backend development, Spring Boot projects, and day-to-day problem solving.

Browse snippetsExplore categories
Interview ready
Production ready
Daily reference

Java quick reference

Developer dashboard

Java snippets

0

Categories

0

Featured

0

10 snippets organized across 9 categories, ready to browse whenever you need them.

Java library overview

A quick snapshot of the Java snippet collection, organized into practical categories for interviews, backend development, and everyday coding.

10

Java snippets

9

Categories

5

Featured

Java

Language

Categories

Explore by topic

Every snippet is grouped into a category — bigger chips mean more snippets are available.

Arrays2
Strings1
HashMap1
Trees1
Graphs1
DP0
Collections1
OOP1
Streams1
Spring1
Featured collection

Most useful Java snippets

Hand-picked snippets that I frequently use in interviews, competitive programming, and backend development.

View all
Editor's pick

Reverse an Array

This snippet demonstrates how to reverse an array efficiently using the two-pointer technique. It swaps elements from both ends of the array until the pointers meet in the middle. This approach is memory-efficient because it performs the reversal in place without requiring an additional array.

arraysTime: O(n) | Space: O(1)ArrayTwo PointersReverse
View snippet
02

Rotate Array by K Positions

arrays·Time: O(n) | Space: O(1)
03

Check Palindrome String

strings·Time: O(n) | Space: O(1)
04

Count Character Frequency using HashMap

hashmap·Time: O(n) | Space: O(n)
05

Remove Duplicates from ArrayList

collections·Time: O(n) | Space: O(n)

Java Library

All Java Snippets

Browse every Java snippet in one place. From arrays and strings to Streams API, Spring Boot and Collections, everything is organized for quick learning and faster development.

Showing 10 of 10 snippets
A
arrays

Reverse an Array

This snippet demonstrates how to reverse an array efficiently using the two-pointer technique. It swaps elements from both ends of the array until the pointers meet in the middle. This approach is memory-efficient because it performs the reversal in place without requiring an additional array.

ArrayTwo PointersReverse
Time: O(n) | Space: O(1)
A
arrays

Rotate Array by K Positions

This snippet demonstrates how to rotate an array to the right by K positions using the reverse algorithm. Instead of shifting elements one by one, it reverses the entire array, then reverses the first K elements and finally the remaining elements. This approach is optimal and widely used in coding interviews due to its O(n) time complexity and O(1) extra space.

ArrayRotationReverse Algorithm
Time: O(n) | Space: O(1)
S
strings

Check Palindrome String

This snippet checks whether a given string is a palindrome using the two-pointer technique. It compares characters from both ends of the string while moving toward the center. If all corresponding characters match, the string is a palindrome; otherwise, it is not. This approach is simple, efficient, and commonly asked in coding interviews.

StringPalindromeTwo Pointers
Time: O(n) | Space: O(1)
H
hashmap

Count Character Frequency using HashMap

This snippet demonstrates how to count the frequency of each character in a string using Java's HashMap. It iterates through every character, updates its count, and finally prints the frequency of each character. This technique is widely used in string manipulation, anagram checking, and text-processing problems during coding interviews.

HashMapStringCharacter Frequency
Time: O(n) | Space: O(n)
C
collections

Remove Duplicates from ArrayList

This snippet demonstrates how to remove duplicate elements from an ArrayList while preserving the insertion order using LinkedHashSet. It is a clean and efficient approach that combines the uniqueness of a Set with the ordered nature of a List. This technique is frequently used in Java applications for data cleaning and interview coding questions.

CollectionsArrayListLinkedHashSet
Time: O(n) | Space: O(n)
O
oop

Sort Objects using Comparable & Comparator

This snippet demonstrates two common ways to sort custom objects in Java: using the Comparable interface for natural ordering and the Comparator interface for custom sorting. Comparable is ideal when a class has a default sorting order, while Comparator provides flexibility to sort objects based on different fields. This is one of the most frequently asked Java interview concepts.

OOPComparableComparator
Time: O(n log n) | Space: O(1)
T
trees

DFS Traversal of Binary Tree

This snippet demonstrates how to perform a Depth-First Search (DFS) traversal on a binary tree using recursion. It uses the Inorder Traversal technique, where the left subtree is visited first, followed by the root node, and then the right subtree. DFS is a fundamental tree traversal algorithm used in binary trees, binary search trees, expression trees, and many interview problems.

TreesBinary TreeDFS
Time: O(n) | Space: O(h)
G
graphs

BFS Traversal using Queue

This snippet demonstrates how to perform a Breadth-First Search (BFS) traversal on a graph using a Queue. BFS explores all neighboring nodes level by level before moving to the next level, making it ideal for finding the shortest path in unweighted graphs, level-order traversal, and connectivity problems. It is one of the most frequently asked graph algorithms in coding interviews.

GraphsBFSQueue
Time: O(V + E) | Space: O(V)
S
streams

Java Stream Filter & Map Example

This snippet demonstrates how to use Java Streams to filter and transform collections efficiently. The filter() method selects elements based on a condition, while the map() method transforms each element into a new value. Streams provide a clean, functional programming style that improves readability and reduces boilerplate code. This is one of the most important Java 8+ features and is frequently asked in Java interviews.

Java StreamsStreams APIFilter
Time: O(n) | Space: O(n)
S
springboot

REST Controller Example in Spring Boot

This snippet demonstrates how to create a simple REST API using Spring Boot. It showcases the use of the @RestController annotation, request mapping, path variables, and HTTP GET endpoints. REST Controllers are the foundation of modern backend development and are widely used for building scalable web services and APIs. This is one of the most frequently asked Spring Boot interview topics for Java backend developers.

Spring BootREST API@RestController
Time: O(1) Space: O(1)

Keep Learning ☕

Every snippet here represents practical Java knowledge collected from interview preparation, backend development, competitive programming, and real-world projects.

Ready To Build?

Open for exciting opportunities, collaborations and ambitious ideas.