Linked Questions
84 questions linked to/from How can I pad a String in Java?
265
votes
24
answers
462k
views
How to format a Java string with leading zero? [duplicate]
Here is the String, for example:
"Apple"
and I would like to add zero to fill in 8 chars:
"000Apple"
How can I do so?
296
votes
20
answers
558k
views
Left padding a String with Zeros [duplicate]
I've seen similar questions here and here.
But am not getting how to left pad a String with Zero.
input: "129018"
output: "0000129018"
The total output length should be TEN.
4
votes
4
answers
16k
views
Java String Padding with spaces [duplicate]
Friends I have to impliment something in project, I found some difficulties, and is as follows:
String name1 = "Bharath" // its length should be 12
String name2 = "Raju" // its length should be ...
4
votes
0
answers
5k
views
how can I use padTo for padding to the left? [duplicate]
I have a number, I want to pad this number with zero's in the beginning if the digits are less that 9 digits.
currently if I have a number lets say:
val num = "123"
if I use padTo(9,"0") I will get "...
1
vote
3
answers
4k
views
how to pad space within a string in java? [duplicate]
Possible Duplicate:
How can I pad a String in Java?
I have a stuation in which my method1() return the string of various size and I want to display the string in a fix space (say length 50 ...
1
vote
2
answers
840
views
C# padding right equivalent in java? [duplicate]
I am trying to convert the following code which is in c# to java. And I am facing difficulty in converting it. Please can anyone suggest me a simple way to do it in Java.
if (Password.Length <= 8)...
-3
votes
3
answers
438
views
How to adjust characters in JAVA [duplicate]
I am new to Java and I am trying make the hashtags to adjust to my text. For example, if I write "message hello, how are you?" I want it to print with capital letters and that the hashtags adjust ...
0
votes
3
answers
193
views
Fastest way to create String of length 'x' all composed of char 'c' in Java [duplicate]
I have an application that is creating a flat file for a legacy application. Something that is common when creating flat files is having to "pad" empty fields with either zeros or spaces. Today, the ...
0
votes
2
answers
100
views
How do I get back all the original leading and trailing spaces I removed from using .trim? [duplicate]
I made a string into .trim(). I wanted to try and reverse it, but I can't seem to do it.
For example,
String a = " apple ";
I did, a = a.trim(); such that:
assert(a == "apple");
I want to ...
1
vote
4
answers
121
views
Formatting within a string [duplicate]
Within a method, I have the following code:
s = s + (items[i] + ":" + numItems[i]+" @ "+prices[i]+" cents each.\n");
Which outputs:
Candy: 5 @ 50 cents each.
Soda: 3 @ 10 cents each.
and so ...
0
votes
1
answer
74
views
Generating a multiplying question with answer in old school style with java [duplicate]
Hello I am trying to make a random Multiplication question generator with the answer in this style.
850702
× 841
-------------------
850702
3402808×
6805616××
-------------------
715440382
...
0
votes
3
answers
144
views
How to change number length format? [duplicate]
By the given task, the numbers can be 000, 001, 002 and so on.
How can I save this number format?
int i = 000;
i++;
System.out.println(i); //the output is 1 but I want 001
So how can I have the ...
0
votes
2
answers
61
views
How to fix weird formatting when printing arrays, using \t [duplicate]
I'm working on a code which prints an array of locations, either in ascending or descending order. However, the formatting is all wrong for two out of 12 locations.
Code:
import java.util.*;
import ...
0
votes
0
answers
35
views
How can I create vertical bars at a specific position after a value? [duplicate]
I built a table in Java. Now I want to close the right side of the table using vertical bars. I want it to loke like this:
+------------------------------+--------+--------+--------+--------+----------...
127
votes
3
answers
29k
views
What are the big improvements between guava and apache equivalent libraries?
We currently use apache collections, string utils, etc. I need to decide if we should switch from the apache foundations implementation.
The important criteria is ease of developers use. Performance/...