- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
concat(), replace(), and trim() Strings in Java.
The concat() method of the String class appends one String to the end of another. The method returns a String with the value of the String passed into the method, appended to the end of the String, used to invoke this method.
Example
public class Test { public static void main(String args[]) { String s = "Strings are immutable"; s = s.concat(" all the time"); System.out.println(s); } }
Output
Strings are immutable all the time
This replace() method of the String class returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
Example
public class Test { public static void main(String args[]) { String Str = new String("Welcome to Tutorialspoint.com"); System.out.print("Return Value :" ); System.out.println(Str.replace('o', 'T')); System.out.print("Return Value :" ); System.out.println(Str.replace('l', 'D')); } }
Output
Return Value :WelcTme tT TutTrialspTint.cTm Return Value :WeDcome to TutoriaDspoint.com
This trim() method of the String class returns a copy of the string, with leading and trailing whitespace omitted.
Example
import java.io.*; public class Test { public static void main(String args[]) { String Str = new String(" Welcome to Tutorialspoint.com "); System.out.print("Return Value :" ); System.out.println(Str.trim() ); } }
Output
Return Value :Welcome to Tutorialspoint.com
- Related Articles
- Trim off '?' from strings in JavaScript
- Difference between concat() and + operator in Java
- How to trim all strings in an array in PHP ?
- Does Swift have a Trim Method for Strings?
- LongStream concat() method in Java
- DoubleStream concat() method in Java
- IntStream concat() method in Java
- Ints concat() function in Java
- How to concatenate strings using both GROUP_CONCAT() and CONCAT() in the same MySQL query?
- Java String concat() method
- How can I use MySQL replace() to replace strings in multiple records?
- Java String trim() method example.
- Comparing Strings and Portions of Strings in Java
- Trim a string in Java to remove leading and trailing spaces
- Java string concat() method vs "+" operator

Advertisements