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
Which of the following statements is true of licensing procedures for IT professionals?
melomori [17]

Answer:

the correct answer is b

Explanation:

4 0
3 years ago
Read 2 more answers
Carlos, an algebra teacher, is creating a series of PowerPoint presentations to use during class lectures. After writing, format
yarga [219]

Answer:

see explanation

Explanation:

Carlos can make a copy of the old presentation that preserves all the formatting, and replace old content with new information.

5 0
3 years ago
To find the ____, the net present value of the system is calculated by combining the net present value of the costs of the syste
Diano4ka-milaya [45]

Answer: c) Return on investment (ROI)

Explanation:

Return on investment (ROI)  is defined as term that measures the performance of single investment efficiency or numerous investment plans. It evaluates and assess plan of investment in form of ratio or percentage.

  • Return of investment(ROI) plan is calculated through dividing the return of investment by investment cost.
  • Other options are incorrect because cash return on capital invested ,carried forward(CF) and BI (business intelligence) are not used for calculating the investment plan through cost and benefit.Thus, the correct option is option(c)
8 0
3 years ago
Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may
RoseWind [281]

Answer:

while ( num >= 0) { ... }

Explanation:

Required

Express to execute a while loop with the given condition.

The condition in the question is that: the user input must be greater than or equal to 0.

The statement for this is:

while ( num >= 0) { ... }

Where num is the input variable

8 0
2 years ago
Please Help Me!!! 40 Points!! Match the correct definition to each term
fgiga [73]

Answer:

is there anymore to this problem because I would like to help you out more mate.

6 0
3 years ago
Other questions:
  • Write a function max arguments. write a program that reads three floating-point numbers, uses the max function, and displays the
    5·1 answer
  • Compare GBN, SR, and TCP (no delayed ACK). Assume that the timeout values for all three protocols are sufficiently long such tha
    7·1 answer
  • A. True
    8·1 answer
  • Which is an advantage that electronic scheduling tools have over paper calendars?
    13·2 answers
  • What arw two reasons for maintaning your privacy on the internet
    11·2 answers
  • To what would you compare the transport layer?
    14·1 answer
  • What is single user operating system? Write two examples.​
    12·2 answers
  • Which online note-taking device allows students to clip a page from a website and reuse it later?
    13·2 answers
  • which of the following are good ways for virtual team members to get to know one another? (choose every correct answer.)
    15·1 answer
  • Make The PYTHON Code<br><br> print first 3 character of a string - given "Seattle" expected "Sea"
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!