slug
type
status
category
summary
date
tags
password
icon

Topic: String Manipulation

Codes:

String manipulation in Java involves various operations that can be performed on strings, such as concatenation, comparison, substring extraction, conversion, and searching, among others. Java provides a rich set of methods within the String class for these purposes. Here's a quick overview of some common string manipulation techniques in Java:

1. Concatenation

Concatenating strings involves joining two or more strings end-to-end. In Java, this can be done using the + operator or the concat method.

2. Comparison

To compare two strings for equality, you can use the equals method. To ignore case during comparison, use equalsIgnoreCase.

3. Substring

Extracting a substring involves creating a new string from a part of an existing string. Use the substring method for this purpose.

4. Conversion

You can convert the case of strings using toUpperCase and toLowerCase.

5. Searching

To find the position of a character or substring within a string, use indexOf or lastIndexOf.

6. Length

To get the length of a string (number of characters), use the length method.

7. Replacing Characters or Substrings

Replace parts of a string using the replace method.

8. Splitting Strings

To split a string into an array of substrings based on a delimiter, use the split method.

9. Trimming

Remove leading and trailing spaces from a string with trim.

10. Converting Between Strings and Arrays

Convert a string to a character array or vice versa.
Remember, strings in Java are immutable. Every time you manipulate a string, a new String object is created. For operations involving frequent modifications, consider using StringBuilder or StringBuffer for better performance.

Questions:

  1. 大小写变换
     

    Solutions:

    1.
     

     
     
    Cracking CSA: Array and ArraylistCracking CSA:Inheritance and Polymorphism
    Loading...