Remove extra white spaces between words. Only one white space is allowed between words. If more than one, remove it. If given string has leading or trailing white spaces, remove them as well. Do not use trim method. Write your own logic.
Example:
You entered with spaces: ” Make Selenium Easy ”
String after removing extra white space: “Make Selenium Easy”
This program was asked in Sapient.
package StringPrograms; import java.util.Scanner; public class RemoveExtraWhiteSpacesBetweenWords { public static String removeExtraWhitespace(String str) { // Convert given string to a char array char[] c = str.toCharArray(); // Output string variable String stringWithoutExtraWhitespaces = ""; // For loop for (int i = 0; i
Output:
Please enter the string to trim extra whitespaces: Make Selenium Easy You entered with spaces: " Make Selenium Easy " String after removing extra white space: "Make Selenium Easy" =================================================================== Please enter the string to trim extra whitespaces: Make selenium easy You entered with spaces: "Make selenium easy" String after removing extra white space: "Make selenium easy" ====================================================================
#HappyCoding
My name is Amod Mahajan and I am an IT employee with 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning
By default a Test method is executed for all data set returned by DataProvider. The reason behind this is that…
In last post, we have learnt how can we make parameterized DataProvider method in TestNG to provide test data to…
"DataProvider" is an important feature provided by TestNG to provide required test data to test methods to run on. We…
Hello Folks, This interview question was asked in Deloitte. Write a java program to Trim a given string without using…
Hello, DataProvider is an important functionality provided by TestNG to achieve Data driven testing or providing a set of different…
Hello Folks, As part of ongoing series on DataProvider, we will learn "How does Encapsulation ( in OOPS concept) help in…