Samual Sam has Published 2310 Articles

Conversion characters for date in Java

Samual Sam

Samual Sam

Updated on 27-Jun-2020 05:14:05

166 Views

The following are the conversion characters for date-time −CharacterDescriptioncComplete date and timeFISO 8601 dateDU.S. formatted date (month/day/year)T24-hour timer12-hour timeR24-hour time, no secondsYFour-digit year (with leading zeroes)yLast two digits of the year (with leading zeroes)CFirst two digits of the year (with leading zeroes)BFull month namebAbbreviated month namemTwo-digit month (with leading zeroes)dTwo-digit ... Read More

Java Program to convert int to binary string

Samual Sam

Samual Sam

Updated on 26-Jun-2020 16:33:49

5K+ Views

The Integer.toBinaryString() method in Java converts int to binary string.Let’s say the following are our integer values.int val1 = 9; int val2 = 20; int val3 = 2;Convert the above int values to binary string.Integer.toBinaryString(val1); Integer.toBinaryString(val2); Integer.toBinaryString(val3);Example Live Demopublic class Demo {    public static void main(String[] args) {     ... 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

359 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

236 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

191 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

3K+ 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

267 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

Search index of a character in a string in Java

Samual Sam

Samual Sam

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

1K+ 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

138 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

774 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