
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

1K+ Views
In this article, we will learn to print unique values from a List in Java. This program will use a loop-based approach to identify and display only the values that appear once, skipping any duplicates. This approach is helpful when working with datasets where you want to remove repeated items and focus on distinct entries. Problem Statement Write a program in Java to print unique values from a list. Below is a demostration of the same − Input 55, 67, 99, 11, 54, 55, 88, 99, 1, 13, 45 Output The distinct elements in the array are 55 67 99 11 ... Read More

736 Views
Finding close matches to a string from a list of words is a common problem in string manipulation and pattern recognition. This article demonstrates two effective approaches for solving this problem in Java. The first approach utilizes string encoding to identify similar patterns, while the second approach leverages the Levenshtein Distance algorithm to find approximate matches. String Encoding Approach The string encoding approach is a clever technique where each string is transformed into a unique encoded format. Strings with the same encoded pattern are considered matches HashMap A HashMap in Java is a collection that stores key-value pairs, where keys ... Read More

980 Views
In this article, we will learn to remove duplicate words from a given sentence in Java. The first method uses Java Streams to remove duplicates and join the words back into a sentence using the distinct() and Collectors.joining() methods. The second method uses a Set to automatically filter out duplicate words and a StringJoiner to combine the words back into a sentence. Both methods will give a sentence with only unique words. Different approaches Following are the different approaches to remove all duplicate words from a given sentence − Using Java Streams ... Read More

5K+ Views
To sort words of sentence in ascending order, the Java code is as follows −Example Live Demoimport java.util.*; public class Demo{ static void sort_elements(String []my_str, int n){ for (int i=1 ;i= 0 && temp.length() < my_str[j].length()){ my_str[j+1] = my_str[j]; j--; } my_str[j+1] = temp; } } public static void main(String args[]){ String []my_arr = {"This", "is", "a", "sample"}; int len = my_arr.length; sort_elements(my_arr,len); System.out.print("The sorted array is : "); for (int i=0; i

828 Views
To split the Even and Odd elements into two different lists, the Java code is as follows −Example Live Demoimport java.util.Scanner; public class Demo{ public static void main(String[] args){ int n, j = 0, k = 0; Scanner s = new Scanner(System.in); System.out.println("Enter the number of elements required :"); n = s.nextInt(); int my_arr[] = new int[n]; int odd_vals[] = new int[n]; int even_vals[] = new int[n]; System.out.println("Enter the elements of the array(even and add numbers) ... Read More

2K+ Views
In this article, we will learn to find missing and additional values in two lists in Java. By the end of this program, you'll be able to detect elements that exist in one list but not in the other, helping you better manage and analyze data in list comparisons. Problem Statement Write a program in Java to find missing and additional values in two lists. Below is the demostration − Input 101, 90, 34, 34, 67, 90 Output The missing element is : 101The new element in the list is : 67 Steps to find missing and additional values in two ... Read More

397 Views
To generate random numbers in a given range, the Java code is as follows −Example Live Demoimport java.util.Random; import java.util.*; public class Demo{ public static void main(String args[]){ Random my_rand = new Random(); List my_list_1 = new ArrayList(); int v_1 = my_rand.nextInt(1000); int v_2 = my_rand.nextInt(967); int v_3 = my_rand.nextInt(1050); int v_4 = my_rand.nextInt(10000); int v_5 = my_rand.nextInt(100); my_list_1.add(v_1); my_list_1.add(v_2); my_list_1.add(v_3); my_list_1.add(v_4); my_list_1.add(v_5); ... Read More

5K+ Views
Splitting and join a string To split and join a string in Java, use the split() and join() method as in the below example − Example A class named 'Demo' contains the main function. Here a String object is defined and split based on the '_' value up to the last word. A 'for' loop is iterated over, and the string is split based on the '_' value. Again, the string is joined using the 'join' function, and the output is displayed. public class Demo{ public static void main(String args[]){ String ... Read More

1K+ Views
Let’s say we have an Octal number. To convert Octal to other bases like binary, hexadecimal, etc, the Java code is as follows −Example Live Demopublic class Demo{ public static String base_convert(String num, int source, int destination){ return Integer.toString(Integer.parseInt(num, source), destination); } public static void main(String[] args){ String my_num = "345"; int source = 8; int destination = 2; System.out.println("Converting the number from octal to binary: "+ base_convert (my_num, source, destination)); destination = 10; System.out.println("Converting the number ... Read More

3K+ Views
Let us see how to write an empty function in Java −Example Live Demoimport java.util.Vector; public class Demo{ public static void my_empty_fun(){ } public static void main(String[] args){ System.out.println("In the main function"); my_empty_fun(); } }OutputIn the main functionAn empty function is basically creating a function without defining any operations inside it. A class named Demo contains an empty function named ‘my_empty_fun’ which is just completed by placing two flower brackets, without adding any functionality into it. In the main function, a print statement is written after which the empty function ... Read More