Is there a Java method equivalent to C#’s Padright()?

Asked

Viewed 54 times

1

I need to fill a string with blanks if I don’t use all the space.

In C#, briefly I do as follows:

Console.WriteLine("-----------------------------------------------------------------------");
        Console.WriteLine("                     RELATÓRIO GERAL DE DIFERENÇAS              ");
        Console.WriteLine($"         DO DIA {data1.getDia()} de {nome_mes.Item1.ToUpper()} DE {data1.getAno()} AO DIA {data2.getDia()} DE {nome_mes2.Item1.ToUpper()} DE {data2.getAno()}");
        Console.WriteLine("-----------------------------------------------------------------------");
        Console.WriteLine($"DIFERENÇA EM DIA(S):      ......................... {diferenca.ToString().PadRight(bteQtdWhiteSpace, ' ')} dia(s)");
        Console.WriteLine($"DIFERENÇA EM SEMANA(S):   ......................... {Math.Round(diferenca / 7).ToString().PadRight(bteQtdWhiteSpace, ' ')} semana(s)*");
  • 2

    the StringUitls has the rightPad, and you could do something using String.format() also

1 answer

3


Browser other questions tagged

You are not signed in. Login or sign up in order to post.