Blog

python tutorials and learn python

Created with Sketch.

Java Program to Compare Strings

Java Program to Compare Strings In this program, you’ll learn to compare two strings in Java. Example 1: Compare two strings public class CompareStrings { public static void main(String[] args) { String style = “Bold”; String style2 = “Bold”; if(style == style2) System.out.println(“Equal”); else System.out.println(“Not Equal”); } } When you run the program, the output…
Read more

Java Program to Lookup enum by String value

Java Program: Looking Up Enums by String Value Introduction In Java, enums provide a way to represent a fixed set of constants. Enum constants are typically defined using uppercase letters, but there might be situations where you need to look up an enum based on its associated string value. This blog post presents a Java…
Read more

Java Program to Convert OutputStream to String

Java Program to Convert OutputStream to String In this extensive blog post, we will explore the concept of converting an OutputStream to a String in Java. We’ll present a Java program that demonstrates how to achieve this conversion and discuss the underlying logic and step-by-step code analysis. The article aims to provide a comprehensive understanding…
Read more

Java Program to Convert InputStream to String

Java Program to Convert InputStream to String In this program, you’ll learn to convert input stream to a string using InputStreamReader in Java. Example: Convert InputStream to String import java.io.*; public class InputStreamString { public static void main(String[] args) throws IOException { InputStream stream = new ByteArrayInputStream(“Hello there!”.getBytes()); StringBuilder sb = new StringBuilder(); String line;…
Read more

Java Program to Convert File to byte array and Vice-Versa

Java Program to Convert File to byte array and Vice-Versa In this program, you’ll learn to convert a File object to byte[] and vice-versa in Java. Before we convert a file to byte array and vice-versa, we assume we have a file named test.txt in our src folder. Here’s the content of test.txt This is…
Read more

Java Program to Convert a Stack Trace to a String

Java Program to Convert a Stack Trace to a String In this program, you’ll learn to convert a stack trace to a string in Java. Example: Convert stack trace to a string import java.io.PrintWriter; import java.io.StringWriter; public class PrintStackTrace { public static void main(String[] args) { try { int division = 0 / 0; }…
Read more

Java Program to Append Text to an Existing File

Java Program to Append Text to an Existing File In this program, you’ll learn different techniques to append text to an existing file in Java. Before we append text to an existing file, we assume we have a file named test.txt in our src folder. Here’s the content of test.txt This is a Test file.…
Read more

Java Program to Create String from Contents of a File

Java Program to Create String from Contents of a File In this program, you’ll learn different techniques to create a string from concents of a given file in Java. Before we create a string from a file, we assume we have a file named test.txt in our src folder. Here’s the content of test.txt This…
Read more

Java Program to Convert Byte Array to Hexadecimal

Java Program to Convert Byte Array to Hexadecimal In this program, you’ll learn different techniques to convert byte array to hexadecimal in Java. Example 1: Convert Byte Array to Hex value public class ByteHex { public static void main(String[] args) { byte[] bytes = {10, 2, 15, 11}; for (byte b : bytes) { String…
Read more

Java Program to Convert Array to Set (HashSet) and Vice-Versa

Java Program to Convert Array to Set (HashSet) and Vice-Versa In this program, you’ll learn to convert an array to a set and vice versa in Java. Example 1: Convert Array to Set import java.util.*; public class ArraySet { public static void main(String[] args) { String[] array = {“a”, “b”, “c”}; Set<String> set = new…
Read more