
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 9150 Articles for Object Oriented Programming

238 Views
Use Arrays.equals() method to compare two Boolean Arrays. Let us first create some arrays to be compared. For using this method, you need to import the following package −import java.util.Arrays;We have 4 arrays and value “true” and “false” are assigned to them.boolean[] myArr1 = new boolean[] { true, false, true, true, true }; boolean[] myArr2 = new boolean[] { true, false, true, true , true }; boolean[] myArr3 = new boolean[] { false, false, true, true, true }; boolean[] myArr4 = new boolean[] { true, false, false, true , false };Now, let us compare Boolean arrays 1 and 2.Arrays.equals(myArr1, myArr2);In ... Read More

589 Views
To get the string representation of Boolean, use the toString() method.Firstly, we have used the valueOf() method for Boolean object and set a string value.Boolean val = Boolean.valueOf("false");The same is then represented using “toString() method.val.toString();Let us see the complete example that prints the string representation of Boolean (True and False) in Java.Example Live Demopublic class Demo { public static void main(String[] args) { // false Boolean val = Boolean.valueOf("false"); System.out.println("Displaying the string representation of Boolean"); System.out.println(val.toString()); // true val = Boolean.valueOf("true"); ... Read More

258 Views
The valueOf() method returns the relevant Number Object holding the value of the argument passed. The argument can be a primitive data type, String, Boolean, etc. Therefore, to parse a string to a Boolean object, use the Java valueOf() method.The following is an example showing how to parse a string to a Boolean object in Java.Example Live Demopublic class Demo { public static void main(String[] args) { System.out.println("Parsing a string to a Boolean object..."); Boolean val = Boolean.valueOf("true"); System.out.println("Value: "+val); } }OutputParsing a string to a Boolean object... Value: trueBoolean ... Read More

13K+ Views
To display Boolean type, firstly take two variables and declare them as boolean.boolean val1, val2;Then one by one assign values to both of them, one of them is shown below −val1 = true;Now, use if statement to check and display the Boolean true value.if(val1) System.out.println("This is true and will get displayed!");Let us now see the complete example to work with Boolean Type in Java.Example Live Demopublic class Demo { public static void main(String[] args) { boolean val1, val2; System.out.println("Boolean Type in Java"); val1 = true; if(val1) ... Read More

1K+ Views
Overflow occurs when the given value is more than the maximum prescribed size of a data type. The overflow condition can result to an error or now the implementation of the programming language handles it on its own.To display overflow of datatypes, I have taken an example of float datatype. Float data type is a single-precision 32-bit IEEE 754 floating point.The range of a float datatype is −approximately ±3.40282347E+38FThe following program display overflow of datatypes in Java.Example Live Demopublic class Demo { public static void main(String[] args) { System.out.println("Displaying Overflow... "); float val1 = ... Read More

3K+ Views
Every data type in Java has a minimum as well as maximum range, for example, for Float.Min = 1.4E-45 Max = 3.4028235E38Let’s say for Float, if the value extends the maximum range displayed above, it leads to Overflow.However, if the value is less than the minimum range displayed above, it leads to Underflow.The following is the Java Program to display the minimum and maximum value of primitive data types.Example Live Demopublic class Demo { public static void main(String[] args) { System.out.println("Integer Datatype values..."); System.out.println("Min = " + Integer.MIN_VALUE); System.out.println("Max = " ... Read More

18K+ Views
Primitive datatypes are predefined by the language and named by a keyword in Java. Here is an example to display the default value of primitive data types.Example Live Demopublic class Demo { static boolean val1; static double val2; static float val3; static int val4; static long val5; static String val6; public static void main(String[] args) { System.out.println("Default values....."); System.out.println("Val1 = " + val1); System.out.println("Val2 = " + val2); System.out.println("Val3 = " + val3); System.out.println("Val4 = " + val4); ... Read More

4K+ Views
A stack and a heap are used for memory allocation in Java. However, the stack is used for primitive data types, temporary variables, object addresses etc. The heap is used for storing objects in memory.Stacks and heaps in Java are explained in more detail as follows −Stack in JavaStacks are used to store temporary variables, primitive data types etc. A block in the stack exists for a variable only as long as the variable exists. After that, the block data is erased and it can be used for storing another variable.

696 Views
This example shows how to search the minimum and maximum element in an array by using Collection.max() and Collection.min() methods of Collection class.Example Live Demoimport java.util.Arrays; import java.util.Collections; public class Main { public static void main(String[] args) { Integer[] numbers = { 8, 2, 7, 1, 4, 9, 5}; int min = (int) Collections.min(Arrays.asList(numbers)); int max = (int) Collections.max(Arrays.asList(numbers)); System.out.println("Min number: " + min); System.out.println("Max number: " + max); } }OutputThe above code sample will produce the following result.Min number: 1 Max number: 9Another ... Read More

2K+ Views
In order to get frequency of each in a string in Java we will take help of hash map collection of Java.First convert string to a character array so that it become easy to access each character of string.Now compare for each character that whether it is present in hash map or not in case it is not present than simply add it to hash map as key and assign one as its value.And if character is present than find its value which is count of occurrence of this character in the string (initial we put as 1 when it ... Read More