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
Programming Articles - Page 1854 of 3366
280 Views
Precondition to check if the list passed as parameter is empty or not. Let us see an example −Examplepublic void my_fun(List myList){ if (myList == null){ throw new IllegalArgumentException("List is null"); } if (myList.isEmpty()){ throw new IllegalArgumentException("List is empty"); } my_fun(myList); }A void function named ‘my_fun’ is defined that takes a list of objects as its parameters. If the list is null, it prints the relevant message. If the list has no elements in it, a specific message is displayed. The function is called by passing the list as ... Read More
733 Views
In this article, we will learn to print a matrix in a "Z" pattern in Java. It starts from the top-left corner, moves horizontally across the top row, then diagonally down through the center, and finally across the bottom row. This pattern creates a "Z" shape with selected elements from the matrix. Problem Statement Write a program in Java to print a matrix in Z form. Input my_arr[][] = { { 34, 67, 89, 0}, { 0, 1, 0, 1 }, { 56, 99, 102, 21 }, {78, 61, 40, 99}} Output The matrix is34 67 89 0 0 99 ... Read More
937 Views
In this article, we will learn how to generate and print all distinct permutations of a given string using Java. Permutations are rearrangements of characters in a string, and this program will ensure that no duplicate permutations are printed. The method works by checking each rearrangement and avoiding any repeats. Problem Statement Write a program in Java to print distinct permutations of a given string − Input my_str = "mnqm" Output The distinct permutations of the string are[mnqm, nmqm, nqmm, mqnm, qmnm, qnmm, mqmn, qmmn, mnmq, nmmq, mmnq, mmqn] Steps to print distinct permutations of a string Following are the ... Read More
377 Views
Example Live Demopublic class Main{ static volatile boolean exit = false; public static void main(String[] args){ System.out.println("Starting the main thread"); new Thread(){ public void run(){ System.out.println("Starting the inner thread"); while (!exit){ } System.out.println("Exiting the inner thread"); } }.start(); try{ Thread.sleep(100); } catch (InterruptedException e){ ... Read More
122 Views
Joiner provides various methods to handle joining operations on string, objects, etc. Let us see an example −Exampleimport com.google.common.base.Joiner; import java.util.*; public class Demo{ public static void main(String[] args){ String[] my_arr = { "hel", null, "lo", "wo", "r", null, "ld" }; System.out.println("The original array is : "+ Arrays.toString(my_arr)); String my_result = Joiner.on('+').skipNulls().join(my_arr); System.out.println("The joined string is : " + my_result); } }OutputThe original array is [hel, null, lo, wo, r, null, ld] The joined string is hel+lo+wo+r+ldA class named Demo contains the main function, which defines ... Read More
3K+ Views
To print single and multiple variables in Java, the code is as follows −Example Live Demopublic class Demo { public static void main(String args[]){ String name_1 = "Hello"; String name_2 = "World"; System.out.println("Printing single variable"); System.out.printf("%s", name_1); System.out.println("Printing multiple variables"); System.out.printf("First Name: %sLast Name: %s",name_1, name_2); } }OutputPrinting single variable Hello Printing multiple variables First Name: Hello Last Name: WorldA class named Demo contains the main function, which defines two strings. These strings are displayed using the ‘println’ function and using the ‘printf’ function.
681 Views
In this article, we will learn the LinkedHashMap and LinkedHashSet in Java. LinkedHashMap Hash table and linked list implementation of the Map interface, with predictable iteration order. Example Let us see an example − import java.util.*; public class Demo { public static void main(String args[]){ LinkedHashMap my_set; my_set = new LinkedHashMap(); my_set.put(67, "Joe"); my_set.put(90, "Dev"); my_set.put(null, "Nate"); my_set.put(68, "Sara"); ... Read More
353 Views
Java is a powerful and versatile programming language. It is used in various applications. It's known for its reliability, portability, and safety, which makes it a famous desire for developers. Java is likewise exceptionally easy to analyze, which makes it a terrific desire for novices. However, it's critical to remember that simplicity might operate as an obstacle. If you're not mindful, you could be caught by Java's accessibility and neglect to explore the unique opportunities the language offers. Let's have a look at some tips to assist you develop as a Java developer and improve your language proficiency. Tip 1: ... Read More
1K+ Views
To convert floating to binary, the Java code is as follows −Example Live Demoimport java.io.*; public class Demo { static void decimal_to_bin(int n){ int[] bin_num = new int[50]; int i = 0; while (n > 0){ bin_num[i] = n % 2; n = n / 2; i++; } for (int j = i - 1; j >= 0; j--) System.out.print(bin_num[j]); } public static void main (String[] args){ ... Read More
279 Views
Following is an example showing widening primitive conversion −Example Live Demopublic class Demo { public static void main(String[] args) { System.out.print("H" + "E"); System.out.print('L'); System.out.print('L'); System.out.print('O'); } }OutputHELLOA class named Demo contains the main function. Here, the ‘print’ function is used to print specific characters in double quotes and then in single quotes. When the process of widening primitive conversion happens, the presence of ‘+’ operator is a must. This ‘+’ operator expects integer on both the left hand and right hand sides.