This project focuses on data normalization using the String class. It simulates a real-world scenario where user-provided data (like a city name) contains unnecessary spaces and needs to be formatted.
- Create a
StringvariablecityNamewith the value" Minsk "(including leading/trailing spaces). - Display the string length before and after using the
trim()method. - Display the city name in UPPER CASE and lower case.
Length before trim: 9
Length after trim: 5
Upper case: MINSK
Lower case: minsk
- Language: Java 23
- IDE: IntelliJ IDEA
- Concepts: String methods (trim(), length(), toUpperCase(), toLowerCase()), Immutability, Object types.
The project demonstrates that String objects are immutable. Methods like trim() or toUpperCase() do not modify the original data but return a new object with the modified byte sequence.
package com.yurii.pavlenko;
/**
* Task 15: String manipulation.
* Cleaning up user input and changing case.
*/
public class Task_15_App {
public static void main(String[] args) {
// Initializing with leading and trailing spaces
String cityName = " Minsk ";
// 1. Length before trimming
System.out.println("Length before trim: " + cityName.length());
// 2. Trimming and checking length again
String trimmedCity = cityName.trim();
System.out.println("Length after trim: " + trimmedCity.length());
// 3. Changing case
System.out.println("Upper case: " + trimmedCity.toUpperCase());
System.out.println("Lower case: " + trimmedCity.toLowerCase());
}
}This project is licensed under the MIT License.
Copyright (c) 2026 Yurii Pavlenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...
License: MIT