Samual Sam has Published 2492 Articles

Creating String Object from Character Array in Java

Samual Sam

Samual Sam

Updated on 27-Jun-2020 05:50:37

469 Views

Here is our character array.char[] ch = { 'T', 'E', 'S', 'T'};To create string object from the above character array is quite easy. Add the array to the string parameter as shown below −String str = new String(ch);Example Live Demopublic class Demo {    public static void main(String[] args) {   ... Read More

Creating a string from a subset of the array elements in Java

Samual Sam

Samual Sam

Updated on 27-Jun-2020 05:48:09

349 Views

To get a string from a subset of the character array elements, use the copyValueOf() method. This method returns a String that represents the character sequence in the array specified.Here is our character array.char[] ch = { 'T', 'E', 'S', 'T', 'I', 'N', 'G'};Now, let us create a string from ... Read More

Display nanoseconds with Java Date and Time Conversion Character

Samual Sam

Samual Sam

Updated on 27-Jun-2020 05:39:41

769 Views

To display nanoseconds, use the ‘N’ Date and Time conversion specifier.System.out.printf("Nanoseconds = %tN", d);Example Live Demoimport java.util.Date; public class Demo {    public static void main(String[] args) {       Date d = new Date();       System.out.printf("Nanoseconds = %tN", d);    } }OutputNanoseconds = 092000000

Displaymilliseconds since the epoch with Java Date and Time Conversion Character

Samual Sam

Samual Sam

Updated on 27-Jun-2020 05:37:12

119 Views

To display milliseconds since the epoch, use the ‘Q’ Date and Time conversion specifier.System.out.printf("Milliseconds since epoch = %TQ", d);The above would display milliseconds since.1970-01-01 00:00:00 GMTExample Live Demoimport java.util.Date; public class Demo {    public static void main(String[] args) {       Date d = new Date();       ... Read More

Display localized month name with printf method in Java

Samual Sam

Samual Sam

Updated on 27-Jun-2020 05:35:41

83 Views

To display localized method name in Java, use the ‘B’ conversion character.System.out.printf("Localized month : %TB", d);To display method name in lowercase, use the “%tb”System.out.printf("Localized month : %tB", d);Example Live Demoimport java.util.Date; public class Demo {    public static void main(String[] args) {       Date d = new Date();   ... Read More

Display ISO 8601 standard date in Java

Samual Sam

Samual Sam

Updated on 27-Jun-2020 05:19:00

745 Views

Use the ‘F’ date conversion character to display ISO 8601 standard date.System.out.printf("ISO 8601 standard date = %tF", d);Above, d is a date object.Date d = new Date();Example Live Demoimport java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; public class Demo {    public static void main(String[] args) throws Exception {       Date ... Read More

Integral conversion characters in Java

Samual Sam

Samual Sam

Updated on 27-Jun-2020 05:16:34

107 Views

Intergral conversion characters include the following.CharacterDescription%dInteger%oOctal%xHexadecimal%XHexadecimalExample Live Demopublic class Demo {    public static void main(String[] args) throws Exception {       System.out.printf( "Integer: %d", 889 );       System.out.printf( "Negative Integer: %d", -78 );       System.out.printf( "Octal: %o", 677 );       System.out.printf( "Hexadecimal: %x", ... Read More

Conversion characters for date in Java

Samual Sam

Samual Sam

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

123 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 create Character Array from String Objects

Samual Sam

Samual Sam

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

225 Views

Use the toCharArray() method in Java to create character arrays from string objects. The following is our string.String str = "This is it!";Now, let us create character array from the above string.char[] strArr = str.toCharArray();Example Live Demopublic class Demo {    public static void main(String[] args) {       String ... Read More

Java Program to convert int to binary string

Samual Sam

Samual Sam

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

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

Advertisements