You may know that an unbounded wildcard Set<?> can hold elements of any type, and a raw type Set can also hold elements of any type. What is the difference between them?
Java
LeetCode – Reorder List (Java)
Given a singly linked list L: L0→L1→ … →Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… For example, given {1,2,3,4}, reorder it to {1,4,2,3}. You must do this in-place without altering the nodes’ values. Java Solution Because the problem requires “in-place” operations, we can only change their pointers, not creating a new list. This problem can be solved … Read more
Leetcode – Longest Palindromic Substring (Java)
Finding the longest palindromic substring is a classic problem of coding interview. This post summarizes 3 different solutions for this problem. 1. Dynamic Programming Let s be the input string, i and j are two indices of the string. Define a 2-dimension array “table” and let table[i][j] denote whether a substring from i to j … Read more
Deep Understanding of Arrays.sort()
Arrays.sort(T[], Comparator < ? super T > c) is a method for sorting user-defined object array. The official Java Doc briefly describe what it does, but not much for deep understanding. In this post, I will walk though the key information for deeper understanding of this method. 1. How to Use Arrays.sort(): A Simple Example … Read more
Efficient Counter in Java
You may often need a counter to understand the frequency of something (e.g., words) from a database or text file. A counter can be easily implemented by using a HashMap in Java. This article compares different approaches to implement a counter. Finally, an efficient one will be concluded. UPDATE: Check out Java 8 counter, writing … Read more
The Introduction of Java Memory Leaks
One of the most significant advantages of Java is its memory management. You simply create objects and Java Garbage Collector takes care of allocating and freeing memory. However, the situation is not as simple as that, because memory leaks frequently occur in Java applications.
Top 10 Questions for Java Regular Expression
This post summarizes the top questions asked about Java regular expressions. As they are most frequently asked, you may find that they are also very useful.
Top 10 Questions about Java Exceptions
This article summarizes the top 10 frequently asked questions and answers about Java exceptions.
Top 9 questions about Java Maps
In general, Map is a data structure consisting of a set of key-value pairs, and each key can only appears once in the map. This post summarizes Top 9 FAQ of how to use Java Map and its implemented classes. For sake of simplicity, I will use generics in examples. Therefore, I will just write Map
instead of specific Map
. But you can always assume that both the K and V are comparable, which means K extends Comparable
and V extends Comparable
.
Java hashCode() and equals() Contract for the contains(Object o) Method of Set
The article is about hashCode and equals contract used for the contains(Object o) method in Set.
The substring() Method in JDK 6 and JDK 7
The implementation of the substring(int beginIndex, int endIndex)
method in JDK 6 is different from JDK 7. This post explains the differences. For simplicity reasons, the substring()
method represents the substring(int beginIndex, int endIndex)
method in this post.