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
True / False
blagie [28]

Answer: True

Explanation:

Variable length instructions generally implemented by CISC processors use memory more efficiently than fixed length instruction of RISC processors sets because CISC supports array whereas RISC does not. Also CISC uses more complex addressing modes which consumes less memory cycles and the the program is also reduces. In Fixed length instruction in RISC processor the simple instructions has to be used a number of time which leads to more memory cycles.

7 0
4 years ago
It’s important to consider adjusting a user’s social network permissions (or access) because
Liula [17]
<span>You may not want to share access to social networks with other members of your team. Also you may want to adjust your users social permission for security reasons, just to be on the safe side. A stronger network means you have a lower chance of a hacker breaking through your system.</span>
5 0
3 years ago
How many voltage values can be represented with a 10-bit binary code?
viktelen [127]
Answer is D. 1024
8 bits is enough to represent 256 different numbers. 9 bits is enough to represent 512 numbers. 10 bits can represent 1024 numbers.
8 0
3 years ago
Describe two benefits of the community of replacing the printed copy with an online version.
DiKsa [7]

Answer:

less costs

Explanation:

saves more money

easy to use for everyone

6 0
3 years ago
Can you tell me what to put in these line please!
Harman [31]

Answer:

I know nothing about this

3 0
3 years ago
Other questions:
  • State College charges its departments for computer time usage on the campus mainframe. A student had access to the university co
    10·1 answer
  • If all of Earth's history were squeezed into one 12-hour period, how long ago did Precambrian time end? How long did the Cenozoi
    15·1 answer
  • An important piece of a project is past due date.
    9·2 answers
  • A cyber community is different than a physical community because _________________. A.people can go to restaurants to meet frien
    13·1 answer
  • Which of the following is the most significant outcome of the formation of the SMPTE?
    6·2 answers
  • Which clauses in the Software Engineering Code of Ethics are upheld by a whistleblower (check all that apply). "Respect confiden
    15·1 answer
  • What manages and control the speed of a motherboards buses
    5·1 answer
  • The column boundary, the border to the right of a column, can be dragged until a row is at a desired height. true or false
    14·1 answer
  • Write a program to enter a number and test if it is greater than 45.6. If the number entered is greater than 45.6, the program n
    8·1 answer
  • What methods could you use to set up printing in an organization?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!