
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7442 Articles for Java

868 Views
When method is overloaded in Java, the functions have the same name, and the number of parameters to the function is same. In such cases, if the parameters are non-primitive and have the ability to accept null values, the compiler gets confused when the function is called with a null value, since it can’t choose either of them, because both of them have the ability to accept null values. This results in a compile time error.ExampleBelow is an example showing the same − Live Demopublic class Demo { public void my_function(Integer i) { System.out.println("The function with integer ... Read More

1K+ Views
Multiset is a collection in Java, that helps in order-independent equality, similar to Set structure. But the only difference is that a multiset can also contain duplicate elements.If multiset is visualized as a list, then this wouldn’t be the case since lists can’t hold duplicate values, and list elements are always in a specific order.Multiset can be thought of as a collection that lies somewhere between a list and a set structure. In multiset, the duplicates values are allowed, and there is no guarantee that the elements in a multiset would occur in a specific order. Multiset is also known ... Read More

306 Views
Multimap is a general method to bind the keys with random multiple values. The Multimap framework in Guava has methods that help in dealing with mapping keys to multiple values. Multimap can be visualized as a framework that −Is a collection of mapping from one key to one specific valueIs a collection of mapping from unique key to multiple values, i.e. collection of values.It can be implemented in places that use Map.Advantages of MultimapAn empty collection need not be populated before added a key value pair with the help of the function ‘put’.The ‘get’ method doesn’t return a null, except ... Read More

3K+ Views
In this article, we will learn about multidimensional collections in Java. These collections offer dynamic resizing, flexible data storage, and better memory management compared to traditional arrays. What are Multidimensional collections? Multidimensional collections are also known as Nested collections. It is a group of objects wherein every group has any number of objects that can be created dynamically. They can be stored in any position as well. In the case of arrays, the user would be bound to a specific number of rows and columns, hence multidimensional structure helps create and add elements dynamically. Different Approaches The following are the ... Read More

645 Views
Following is the Java program to search characters and substring in a string −Example Live Demoimport java.io.*; import java.lang.*; public class Demo { public static void main (String[] args) { String test_str = "Hello"; CharSequence seq = "He"; boolean bool_1 = test_str.contains(seq); System.out.println("Was the substring found? " + bool_1); boolean bool_2 = test_str.contains("Lo"); System.out.println("Was the substring found? " + bool_2); } }OutputWas the substring found? true Was the substring found? FalseA class named Demo contains the main function. Here, a string ... Read More

432 Views
Type inference in Java refers to the automatic detection of the variable’s datatype. This automatic detection usually happens at compile time. It is a feature of Java 10 and it allows the developer to skip declaring the type that is associated with the local variables. Local variables are those which are defined inside a method, initialization block, in for-loops, etc. The type would be usually identified by JDK.Upto Java 9, the following syntax was used to define local variable of a class type −class_name variable_name = new class_name(Arguments);This way, the type of the object would be specified on the right ... Read More

3K+ Views
Problem Statement Given a sentence, create a program in Java that swaps the first and last characters of each word efficiently as given below − Input That is a sample Output The string after swapping the last characters of every word is : thaT si a eampls Steps to swap first and last characters of words in a sentence Below are the steps to swap first and last characters of words in a sentence − Convert string to character array. Iterate through the character array using while loop to identify the ... Read More

4K+ Views
In this article, we will learn to merge two files into a third file in Java. Combining the contents of two files into a third file is a typical operation in file handling, frequently needed to aggregate data. Java offers efficient facilities such as BufferedReader and PrintWriter to accomplish this easily. ApproachThe following are the steps to merge the contents of two files into a third file in Java− Read the contents of the first file line by line using a BufferedReader. Write each line to the third file using a ... Read More

701 Views
In this article, we will learn to write a program for shell sort using Java. In the program, we’ll apply this technique to sort an array and observe how the algorithm optimizes the sorting process by reducing the interval between elements. Shell sort Shell sort is a sorting technique that is similar to insertion sort, wherein elements are sorted which are at far ends (either end) of the array. This way, the interval size between the next and the second to last element reduces. This happens for all the elements in the array until the interval distance is reduced to ... Read More

453 Views
In this article, we will learn Pigeonhole Sort in Java, a sorting algorithm designed for arrays with a small range of integer values. It organizes elements into "pigeonholes" based on their values and then reconstructs the sorted array. We’ll discuss two approaches: a basic method using arrays and an optimized approach using LinkedLists. What is Pigeonhole Sort? Pigeonhole Sort works by distributing elements into a range of buckets based on their values. It is most effective when the range of input values is relatively small compared to the size of the dataset. The algorithm ensures stability and simplicity in sorting ... Read More