1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
jekas [21]
3 years ago
13

How do I find a space in my String and replace it? JAVA

Computers and Technology
1 answer:
Fantom [35]3 years ago
8 0

Answer:

This article shows how to use regex to remove spaces in between a String.

A string with spaces in between.

String text = "Hello World Java.";

We want to remove the spaces and display it as below:

Hello World Java.

1. Java regex remove spaces

In Java, we can use regex \\s+ to match whitespace characters, and replaceAll("\\s+", " ") to replace them with a single space.

Regex explanation.

`\\s` # Matches whitespace characters.

+ # One or more

StringRemoveSpaces.java

package com.mkyong.regex.string;

public class StringRemoveSpaces {

public static void main(String[] args) {

String text = "Hello World Java.";

String result = text.replaceAll("\\s+", " ");

System.out.println(result);

}

}

Output

Terminal

Hello World Java.

You might be interested in
Traditionally, remote administrative access on routers was configured using Telnet on TCP port 23. However, Telnet was developed
FinnZ [79.3K]

<u>Explanation</u>:

It is an all-too-often used technology today in connecting several computers together via a network.

Routing simple terms means the action of selecting the path taken by the traffic of data in a network of computers. The routing systems involve the use of both wireless and cable based architectures. Some common example of routing systems includes:

  1. Dynamic Routing
  2. Static routing
  3. Default Routing
5 0
3 years ago
What is the difference between a learner’s license and a driver’s license?
kirill115 [55]

privilege to operate a motor vehicle-drivers License

Able to get when 15. Valid for 1 yr. Allows you to drive with a parent in the car. $15. Bring social security and birth certificate to the DLD. Have for 6 months (and do 40 hrs) before getting license.-Learner Permit

4 0
3 years ago
Which of the following office online apps is most effective for creating
Lorico [155]

Well it really depends on what you are creating. But the most effective app for me for creating photos is Visco.

4 0
3 years ago
Read 2 more answers
If you have downloaded this book's source code from the companion Web site, you will find a file named text.txt in the Chapter 1
Lubov Fominskaja [6]

Answer:

Explanation:

The following python code loops through each line within a file called text.txt and counts all the words, then it divides this count by the number of sentences in the text file. Finally, output the average number of words per sentence.

f = open("text.txt", "r")

all_words = 0

sentences = 0

for x in f:

   list = x.split(' ')

   all_words += len(list)

   sentences += 1

average = all_words / sentences

print("There are an average of " + str(average.__round__()) + " words in each sentence.")

6 0
3 years ago
To place controls on a form in a stacked layout, select all the controls and click the stacked button on the ____ tab.
Sidana [21]
<span>To place controls on a form in a stacked layout, select all the controls and click the stacked button on the Arrange tab.  </span><span>The </span>Arrange<span> tab is located in the  </span>C1ReportDesigner<span>'s Ribbon menu and provides shortcuts to the Edit, Auto Format, Grid, Control Alignment, Position, and Size menu functions. </span>
3 0
3 years ago
Other questions:
  • Choose all statements that identify the benefits of programming design.
    10·2 answers
  • Students are studying the effects of beach pollution by counting populations of seagulls at two different beach locations. One l
    7·1 answer
  • Individuals with desirable traits will be __________ to have young that survive than individuals without these traits. (2 points
    5·2 answers
  • 1.<br> The correct way to use a seat belt is
    8·1 answer
  • ) Which is true about the agile method?
    7·1 answer
  • Biography of bill gates
    8·2 answers
  • The best way to achieve stronger encryption is to
    13·1 answer
  • WIRELESS DATA TRANSMISSION METHODS​
    8·1 answer
  • Full form of http.<br>wrong answer will be reported ​
    6·2 answers
  • What does the word collaborative mean?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!