Use the width and precision specifiers, set to the same value. This will pad strings that are too short, and truncate strings that are too long. The ‘-‘ flag will left-justify the values in the columns.
System.out.printf("%-30.30s %-30.30s%n", v1, v2);
More Related Contents:
- Count from 1-10 using a loop with return values to a 10-element sized single-dimensional array
- How to convert a letter to an another letter in Java [duplicate]
- is it good practice to call a method from Exception block in java?
- Conditionally ignoring tests in JUnit 4
- Which Java Collection should I use?
- Design Patterns: Factory vs Factory method vs Abstract Factory
- Java: Syntax and meaning behind “[B@1ef9157”? Binary/Address?
- Android ListView headers
- Why start an ArrayList with an initial capacity?
- JRE 1.7 – java version – returns: java/lang/NoClassDefFoundError: java/lang/Object
- How can I lookup a Java enum from its String value?
- Automatic cookie handling with OkHttp 3
- The range of int in Java
- Java GIF animation not repainting correctly
- Java: Infinite loop using Scanner in.hasNextInt()
- Including jar files in class path
- Why does appending “” to a String save memory?
- Will Java Final variables have default values?
- Stream video in Java
- Is it possible to write swap method in Java? [duplicate]
- org.openqa.selenium.remote.http.ConnectionFailedException: Unable to establish websocket connection Selenium ChromeDriver and Chrome v111
- Spring security added prefix “ROLE_” to all roles name?
- Spring Boot access static resources missing scr/main/resources
- What’s the difference between requires and requires static in module declaration
- What are annotations and how do they actually work for frameworks like Spring?
- How to convert jar to OSGi bundle using eclipse and bndtools
- Command failed: gradlew.bat installDebug
- MouseListener Help Java
- I need to launch a JFrame from another JFrame and have that run like independent applications, help?
- Maximum number of dimensions in a Java array