Convert Java String Object to Boolean Object

Samual Sam
Updated on 26-Jun-2020 10:38:28

2K+ Views

A string object can be created in Java using the string literal.String myStr = “Amit”;Another way to create a string object is using the new keyword.String myStr = new String("Hello!");We have used the first method to create a string object.String str = "true";Now, use the valueOf() method to convert String Object to Boolean Object. We have used this method on Boolean object.Boolean bool = Boolean.valueOf(str);Let us now see the complete example to show how to convert String Object to Boolean Object.Example Live Demopublic class Demo {    public static void main(String[] args) {       String str = "true";   ... Read More

What is the Human Brain Made Of

Shanmukh Pasumarthy
Updated on 26-Jun-2020 10:38:15

325 Views

In the Central Nervous System, Human Brain is the main organ. It comprises of the cerebrum, the brain stem, and the cerebellum. It controls the vast majority of the body activities, processing, incorporating, and coordinating the data it gets from the sensory organs and deciding the instructions sent to the rest of the body. The mind is contained in and secured by the skull bones of our head.The human cerebrum is mainly made up of neurons, glial cells, and veins. Interneurons, pyramidal cells including Betz cells, motor neurons, and cerebellar Purkinje cells are the various types of neurons. Betz cells are ... Read More

Create Boolean Object from Boolean Value in Java

karthikeya Boyini
Updated on 26-Jun-2020 10:37:57

3K+ Views

To create a Boolean object from Boolean value is quite easy. Create an object with Boolean and set the Boolean value “true” or “false”, which are the Boolean literals.Let us now see how “true” value is added.Boolean bool = new Boolean("true");In the same way, “False” value is added.Boolean bool = new Boolean("false");The following is an example displaying how to create a Boolean object from Boolean value.Example Live Demopublic class Demo {    public static void main(String[] args) {       Boolean bool = new Boolean("true");       System.out.println(bool);       bool = new Boolean("false");       System.out.println(bool); ... Read More

Convert Boolean to String in Java

karthikeya Boyini
Updated on 26-Jun-2020 10:37:05

11K+ Views

To convert Boolean to String in Java, use the toString() method. For this, firstly, we have declared two booleans.boolean bool1 = false; boolean bool2 = true;Now, convert Boolean to String using the toString() method in Java as shown below −String str1 = new Boolean(bool1).toString(); String str2 = new Boolean(bool2).toString();Now, when you will display the values “str1” and “str2”, the output would be in String.Let us now see the complete example to convert Boolean to String.Example Live Demopublic class Demo {    public static void main(String[] args) {       boolean bool1 = false;       boolean bool2 = true; ... Read More

Read Integers from Console in Java

Samual Sam
Updated on 26-Jun-2020 10:36:26

20K+ Views

To read integers from console, use Scanner class.Scanner myInput = new Scanner( System.in );Allow a use to add an integer using the nextInt() method.System.out.print( "Enter first integer: " ); int a = myInput.nextInt();In the same way, take another input in a new variable.System.out.print( "Enter second integer: " ); Int b = myInput.nextInt();Let us see the complete example.Exampleimport java.util.Scanner; public class Demo {    public static void main( String args[] ) {       Scanner myInput = new Scanner( System.in );       int a;       int b;       int sum;       System.out.print( ... Read More

Convert Short to Numeric Primitive Data Types in Java

karthikeya Boyini
Updated on 26-Jun-2020 10:35:31

348 Views

To convert Short to numeric primitive data types, use the following methods −byteValue() shortValue() intValue() longValue() floatValue()Firstly, let us declare a Short.Short shortObj = new Short("40");Now, let us see how to convert it to long type, for a simple example.long val5 = shortObj.longValue(); System.out.println("Long: "+val5);In the same way, you can convert it to other primitive data types as shown in the complete example below.Example Live Demopublic class Demo {    public static void main(String []args) {       Short shortObj = new Short("40");       byte val1 = shortObj.byteValue();       System.out.println("Byte: "+val1);       int val2 ... Read More

Convert Byte Primitive Type to Byte Object in Java

Samual Sam
Updated on 26-Jun-2020 10:33:57

998 Views

To convert byte primitive type to Byte object, use the Byte constructor.Here is our byte primitive type.byte b = 100;Now let us convert it to Byte object.Byte res = new Byte(b);Let us see the complete example.Example Live Demopublic class Demo {    public static void main(String[] args) {       byte b = 100;       Byte res = new Byte(b);       System.out.println(res);    } }Output100

Combine Date and Time from Different MySQL Columns

Samual Sam
Updated on 26-Jun-2020 10:31:06

1K+ Views

You can combine date and time from different MySQL columns to compare with the entire date time with the help of CONCAT() function. The syntax is as follows −SELECT *FROM yourTableName WHERE CONCAT(yourDateColumnName, '', yourTimeColumnName) > 'yourDateTimeValue';To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table DifferentDateTime     -> (     -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,     -> ArrivalDate date,     -> ArrivalTime time     -> ); Query OK, 0 rows affected (1.53 sec)Insert some records in the table using ... Read More

Display Bit Manipulation in Integer using Java

karthikeya Boyini
Updated on 26-Jun-2020 10:29:38

241 Views

Let’s say we have the following decimal number, which is binary 100100110.int dec = 294;To perform bit manipulation, let us count the number of 1 bits in it. We have used bitCount() method for this purpose.Integer.bitCount(dec);The following is an example to display bit manipulation in given Integer.Example Live Demopublic class Demo {    public static void main(String []args) {       // binary 100100110       int dec = 294;       System.out.println("Count of one bits = " + Integer.bitCount(dec));    } }OutputCount of one bits = 4

Fetch Rows Where a Field Value is Less Than 5 Chars in MySQL

Samual Sam
Updated on 26-Jun-2020 10:29:35

737 Views

To fetch rows where a field value is less than 5 chars, you need to use LENGTH() function. The syntax is as follows −SELECT *FROM yourTableName WHERE LENGTH(yourColumnName) < 5;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table fieldLessThan5Chars    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> yourZipCode varchar(10)    -> ); Query OK, 0 rows affected (0.52 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into fieldLessThan5Chars(yourZipCode) values('35801'); Query ... Read More

Advertisements