- 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](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
118 Views
The following is our string.String str = "Jack";Now take a StringBuilder object.StringBuilder strBuilder = new StringBuilder();Perform left padding and extend the string length to 20. The string that will be padded comes on the left.while (strBuilder.length() + str.length() < 20) { strBuilder.append("demo"); }The following is an example wherein we have ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
9K+ Views
The MMMM format for months is like entire month name: January, February, March, etc. We will use it like this.SimpleDateFormat("MMM");Let us see an example.// displaying month in MMMM format SimpleDateFormat simpleformat = new SimpleDateFormat("MMMM"); String strMonth= simpleformat.format(new Date()); System.out.println("Month in MMMM format = "+strMonth);Above, we have used the SimpleDateFormat class, ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
2K+ Views
Let’s say the following is our string.String myStr = "";Now, we will check whether the above string is whitespace, empty ("") or null.if(myStr != null && !myStr.isEmpty() && !myStr.trim().isEmpty()) { System.out.println("String is not null or not empty or not whitespace"); } else { System.out.println("String is null or empty ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
988 Views
The following is our string.String str = "pqrst";In the above string, we want to search for the following set of characters.// set of characters to be searched char[] chSearch = {'p', 'q', r'};For this, loop through the length of the string and check every character in the string “str”. If ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
256 Views
To format date time with Join, set the date as a string and do not forget to add the delimeter.For delimeter “/” in the dateString.join("/", "11", "11", "2018");For delimeter “:” in the date.String.join(":", "10", "20", "20");The following is an example.Example Live Demopublic class Demo { public static void main(String[] args) ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
778 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](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
134 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](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
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](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
496 Views
To format strings into table, use the System.out.format.For our table, we have given 15s, that means 15 spaces. In the same way for the second column after the indices.|%1$-15s|%2$-15s|Added the above in a string, so that we don’t have add it again and again.The following is an example.Example Live Demopublic class ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
Samual Sam
953 Views
The following is our string.String str = "4434";To check whether the above string has only digit characters, try the following if condition that uses matches() method and checks for every character.if(str.matches("[0-9]+") && str.length() > 2) { System.out.println("String contains only digits!"); }Example Live Demopublic class Demo { public static void main(String ... Read More