- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 9321 Articles for Object Oriented Programming
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
125 Views
To compare two Java short arrays, use the Arrays.equals() method.Let us first declare and initialize some short arrays.short[] arr1 = new short[] { 20, 15, 35, 55, 69 }; short[] arr2 = new short[] { 20, 15, 35, 55, 69 }; short[] arr3 = new short[] { 22, 19, 30, 45, 78 };Now let us compare any two of the above arrays.Arrays.equals(arr1, arr2));In the same way, work it for other arrays and compare themExample Live Demoimport java.util.*; public class Demo { public static void main(String []args) { short[] arr1 = new short[] { 20, 15, 35, 55, ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
313 Views
To convert Byte to numeric primitive data types, use the following methods −byteValue() shortValue() intValue() longValue() floatValue()Firstly, let us declare a Byte.Byte byteVal = new Byte("35");Now, let us see how to convert it to long type, for a simple example.long longVal = byteVal.longValue(); System.out.println(longVal);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[]) { // byte Byte byteVal = new Byte("35"); byte b = byteVal.byteValue(); System.out.println(b); ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
315 Views
Here is our string.String str = "Asia is a continent!";Now let us use a byte array and the getBytes() method to fulfill our purpose.byte[] byteVal = str.getBytes();Now, if we will get the length of the array, it would return the length as shown in the complete example below −Example Live Demopublic class Demo { public static void main(String args[]) { String str = "Asia is a continent!"; System.out.println(str); // converted to byte array byte[] byteVal = str.getBytes(); // getting the length System.out.println(byteVal.length); } }OutputAsia is a continent! 20
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
794 Views
To convert byte[] to String, firstly let us declare and initialize a byte array.// byte array byte[] arr = new byte[] {78, 79, 33};Now take a String and include the array in it.String str = new String(arr);Let us see the complete example to convert byte array to String.Example Live Demopublic class Demo { public static void main(String args[]) { // byte array byte[] arr = new byte[] {78, 79, 33}; String str = new String(arr); // string System.out.println("String = "+str); } }OutputString = NO!
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
11K+ Views
To convert hex string to byte array, you need to first get the length of the given string and include it while creating a new byte array.byte[] val = new byte[str.length() / 2];Now, take a for loop until the length of the byte array.for (int i = 0; i < val.length; i++) { int index = i * 2; int j = Integer.parseInt(str.substring(index, index + 2), 16); val[i] = (byte) j; }Let us see the complete example.Example Live Demopublic class Demo { public static void main(String args[]) { String str = "p"; ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
3K+ Views
To check whether the entered value is a digit or not in Java, use the Character.isDigit() method.We have a character to be checked.char val = '5';Now let us use the Character.isDigit() method.if (Character.isDigit(val)) { System.out.println("Character is a digit!"); } else { System.out.println("Character is not a digit!"); }Let us see the complete example now to check for Uppercase in Java.Example Live Demopublic class Demo { public static void main(String []args) { System.out.println("Checking for digit..."); char val = '5'; System.out.println("Value: "+val); if (Character.isDigit(val)) { ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
9K+ Views
To check whether a character is in Lowercase or not in Java, use the Character.isLowerCase() method.We have a character to be checked.char val = 'q';Now let us use the Character.isLowerCase() method.if (Character.isLowerCase(val)) { System.out.println("Character is in Lowercase!"); }else { System.out.println("Character is in Uppercase!"); }Let us see the complete example now to check for Lowercase in Java.Example Live Demopublic class Demo { public static void main(String []args) { System.out.println("Checking for Lowercase character..."); char val = 'q'; System.out.println("Character: "+val); if (Character.isLowerCase(val)) { System.out.println("Character is ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
934 Views
The following is our byte array.byte[] b = new byte[]{'p', 'q', 'r'};We have created a custom method “display” here and passed the byte array value. The same method converts byte array to hex string.public static String display(byte[] b1) { StringBuilder strBuilder = new StringBuilder(); for(byte val : b1) { strBuilder.append(String.format("%02x", val&0xff)); } return strBuilder.toString(); }Let us see the entire example now.Example Live Demopublic class Demo { public static void main(String args[]) { byte[] b = new byte[]{'p', 'q', 'r'}; /* byte array cannot be displayed as String ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
763 Views
To check for Integer overflow, we need to check the Integer.MAX_VALUE with the multiplied integers result, Here, Integer.MAX_VALUE is the maximum value of an integer in Java.Let us see an example wherein integers are multiplied and if the result is more than the Integer.MAX_VALUE, then an exception is thrown.The following is an example showing how to check for Integer overflow.Example Live Demopublic class Demo { public static void main(String[] args) { int val1 = 9898; int val2 = 6784; System.out.println("Value1: "+val1); System.out.println("Value2: "+val2); long mul ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
519 Views
Use the parseInt() method with the second parameter as 2 since it is the radix value. The parseInt() method has the following two forms.static int parseInt(String s) static int parseInt(String s, int radix)To convert binary to decimal, use the 2nd syntax and add radix as 2, since binary radix is 2.Integer.parseInt("1110", 2)Example Live Demopublic class Demo { public static void main( String args[] ) { // converting to decimal System.out.println(Integer.parseInt("1110", 2)); } }Output14