
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 2310 Articles

Samual Sam
1K+ Views
To right pad a string, use the String.format and set the spaces.String.format("%1$-" + 20 + "s", "demotext"));If you add 30 above, it will display the next string after 30 spaces from the beginning.String.format("%1$-" + 30 + "s", "demotext")The following is an example.Example Live Demopublic class Demo { public static void ... Read More

Samual Sam
212 Views
To format a string, use the String.format() method in Java. The following is an example that formats a string %s.Example Live Demopublic class Demo { public static void main(String []args) { String str = String.format("%s %s", "demo", "text"); System.out.print("String: "+str); } }OutputString: demo ... Read More

Samual Sam
2K+ Views
To perform Bubble Sort, try the below given code. In this each each pair of adjacent elements is compared and the elements are swapped if they are not in order.The following is an example.Example Live Demopublic class Demo { public static void main(String []args) { String str[] ... Read More

Samual Sam
605 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

Samual Sam
515 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

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

Samual Sam
196 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

Samual Sam
165 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

Samual Sam
844 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

Samual Sam
152 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