If not, then this is a possible strategy.
#ADD I NUMBER OF 0S TO STRING JAVA HOW TO#
So, if you know for sure that it's an int, khachik's answer works great. How to truncate a java string for a given number of bytes, once UTF-8 is encoded How do I truncate a java String so that I know it will fit in a given number of bytes storage once it is UTF-8. The disadvantage is that if what you're padding is already an int, then you'll have to convert it to a String and back, which is undesirable. The benefit of this over khachik's answer is that this does not use Integer.parseInt, which can throw an Exception (for example, if the number you want to pad is too large like 12147483647). String padded = "000000000000000".substring(unpadded.length()) + unpadded Java program to use StringUtils.leftPad() method to left pad a string with zeros, by adding leading zeros to string. Example: For integer 42, you want to fill it up with leading zeros to the following string with 5 characters. In the following example we convert a number of type double to. How to convert it to a string by adding leading zeros so that the string has a fixed number of positions. You can convert an doubleing point number to string in Java using String class methods. if you want to add zeros to the left so that the whole string is 15 characters long: String unpadded = "12345" The str(i).zfill(5) accomplishes the same string conversion of an integer with leading zeros. You can replace the "#" characters with whatever character you would like to pad with, repeated the amount of times that you want the total width of the string to be. String padded = unpadded + "#".substring(unpadded.length()) If you want to pad right: String unpadded = "12345" To check whether the two string are anagram or not anagram in c programming, you have to ask to the user to enter two string to start checking. Java Program to Count Number of Words in a String - This article is created to cover a program in Java to count the total number of words available in a string entered by user. String padded = "#".substring(unpadded.length()) + unpadded Java Program to Check String is Anagram or Not. This will pad left any string to a total width of 10 without worrying about parse errors: String unpadded = "12345"