Samual Sam has Published 2492 Articles

Convert byte to String in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 16:31:54

743 Views

The valueOf() method is used in Java to convert byte to string.Let’s say we have the following byte value.byte val = 40;Converting the above byte to string.String.valueOf(val);Example Live Demopublic class Demo {    public static void main(String[] args) {       byte val = 40;       // converting ... Read More

Java Program to get the Characters in a String as an Array of Bytes

Samual Sam

Samual Sam

Updated on 26-Jun-2020 16:30:00

239 Views

To get the characters in a string as an array of bytes, use the getBytes() method.Let’s say we have the following string.String str = "Demo Text!";Convert it to array of bytes.byte[] arr = str.getBytes();Example Live Demopublic class Demo {    public static void main(String[] args) {       String str ... Read More

Convert a String to a byte number in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 16:27:46

162 Views

Use the parseByte() method in Java to convert a String to a byte.Let’s say the following is our string −String str = “76”;Now, the parseByte() method converts the string to byte −byte val = Byte.parseByte(str);The following is an example −Example Live Demopublic class Demo {     public static void main(String[] args) throws Exception {        String str = "76";     ... Read More

Java Program to search for last index of a group of characters

Samual Sam

Samual Sam

Updated on 26-Jun-2020 16:15:37

132 Views

Use the lastIndexOf() method to search for last index of a group of characters. Let’s say the following is our string.String myStr = "pqrstuvwxyzpqrst";Searching for the substring “pqrs” in the string to get the last index of its occurring in the string. We begin the search from index 3.int begnIndex ... Read More

Narrowing Conversion in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 16:09:51

2K+ Views

Narrowing conversion is needed when you convert from a larger size type to a smaller size. This is for incompatible data types, wherein automatic conversions cannot be done.Let us see an example wherein we are converting long to integer using Narrowing Conversion.Example Live Demopublic class Demo {     public static void main(String[] args) {        long longVal = 878; ... Read More

Java Program to convert String to Integer using Integer.parseInt()

Samual Sam

Samual Sam

Updated on 26-Jun-2020 15:31:54

188 Views

The Integer.parseInt() method in Java converts a string to an integer.Let’s say the following is our string −String str = "456";Converting it into integer −Integer.parseInt(str));The following is the complete example −Example Live Demopublic class Demo {     public static void main(String[] args) {        String str = "456";        System.out.println(Integer.parseInt(str));     } }Output456Read More

Split String with Dot (.) in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 15:30:03

11K+ Views

Let’s say the following is our string.String str = "This is demo text.This is sample text!";To split a string with dot, use the split() method in Java.str.split("[.]", 0);The following is the complete example.Example Live Demopublic class Demo {     public static void main(String[] args) {        String str = "This is demo text.This is sample text!";       ... Read More

Search index of a character in a string in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 15:28:38

940 Views

Use the indexOf() method to search the index of a character in a string.Let’s say the following is our string.String myStr = "amit";Now, let us find the index of character ‘t’ in the above string.strIndex = myStr.indexOf('t');The following is the final example.Example Live Demopublic class Demo {     public static void main(String[] args) {        String myStr = "amit"; ... Read More

Search for a character from a given position in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 15:10:01

102 Views

Use the indexOf() method to search for a character from a given position.Let’s say the following is our string.String myStr = "Amit Diwan";Here, we are searching for the character “i” in the string. We are beginning the index from 4 for our search.int begnIndex = 4; System.out.println("String: "+myStr); strLastIndex = ... Read More

Get the default system properties in Java

Samual Sam

Samual Sam

Updated on 26-Jun-2020 15:04:28

568 Views

To return all the default systems properties in Java, firstly use the System.getProperties() method.java.util.Properties prop = System.getProperties();After that, use the list() method to list all of them.prop.list(System.out);Example Live Demopublic class Demo {     public static void main(String[] args) {        java.util.Properties prop = System.getProperties();        System.out.println("Here are the Properties:");        prop.list(System.out);     } }OutputHere ... Read More

Advertisements