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
Good participation in music is strictly limited to those who perform well. true or false
sdas [7]
The answer would be false because you don't have to be good at it to participate and try your hardest
8 0
3 years ago
Read 2 more answers
You work as the IT administrator for a small corporate network. To accommodate specific network communication needs for an upcom
Andreas93 [3]

Answer:

The right answer is option A

Explanation:

To upgrade a network communication to accommodate for specific network needs, what is required is to select and install the network interface with the highest speed to connect to the local network.

Network communications are what we use to connect to the internet. There are different network providers and the provided networks do not have the same network speed due to different reasons. A network interface is what is used to connect our computer to the network provider. It is only logical to get the best network interface card in that region and connect to the fastest speed available.

5 0
3 years ago
Who plays Roblox and wants to be friends on it
qaws [65]
I have roblox and I would like to be friends on it
4 0
3 years ago
Read 2 more answers
A user complains that her computer is performing slowly. She tells you the problem started about a week ago when new database so
motikmotik

Answer/Explanation:

It is best to use Performance Monitor and Process counters to observe performance.

Cheers

6 0
3 years ago
What did Muhammad do when he encountered opposition from Mecca’s city leaders? He brought more followers to Mecca. He relocated
Rudiy27

Answer:

He relocated from Mecca to the city of Medina.

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • Use the image below to answer this question.
    14·1 answer
  • Your friend, who is a little computer phobic, is going to create his first web page, and he asks you to recommend some software
    13·1 answer
  • Who usually signs a collection letter?
    15·2 answers
  • "Simon Says" is a memory game where "Simon" outputs a sequence of 10 characters (R, G, B, Y) and the user must repeat the sequen
    12·1 answer
  • If we have a priority queue storing approximately million numbers, and the bottom level is "full", which of the following statem
    9·1 answer
  • The basic input/output system (bios locates the boot loader program on a linux system by reading the __________ on the hard driv
    13·1 answer
  • An advertiser who sells coffee beans adds the keyword "Java'" to an ad group. After two weeks, she runs a placement performance
    11·1 answer
  • (BRAINLIEST QUESTION) What are some challenges that will need to be overcome in order for the Internet of Vehicles to become a r
    13·1 answer
  • If a*b = 2a - 56, calculate the value of<br>3 * 4​
    14·1 answer
  • Which online article citation is correctly formatted according to MLA standards?
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!