- 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
Samual Sam has Published 2492 Articles
Samual Sam
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
Samual Sam
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
Samual Sam
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
Samual Sam
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
Samual Sam
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
Samual Sam
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
Samual Sam
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
Samual Sam
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
Samual Sam
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
Samual Sam
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