5

I want to know if there is any way to print the underlined text on console using java String class.

xlecoustillier
  • 16,183
  • 14
  • 60
  • 85
Harshal Patil
  • 349
  • 1
  • 7
  • 26

4 Answers4

5

You can only rely on how the String is interpreted by your console. For example, in bash, you can do something like inserting your string between escape sequences \033[1m and \033[0m (for bold):

\033[1mInsert your String here\033[0m

You should read the documentation of your favorite console.

Arnaud Denoyelle
  • 29,980
  • 16
  • 92
  • 148
2

I'd have a look at the tput command as outlined in this answer, but it will make your code a bit unreadable as it will look like this

System.out.println("...")
// execute tput
System.out.println("underlined text")
// execute tput
System.out.println("...")

Also, this page may help

Notice I'm assuming you aim for bash like terminal

Community
  • 1
  • 1
David Rabinowitz
  • 29,904
  • 14
  • 93
  • 125
2

I used Netbeans IDE v12.0

String txt="Welcome Back";
String utxt = String.join("\u0332",n.split("",-1));
System.out.println(utxt);
Output
W̲e̲l̲c̲o̲m̲e̲ ̲B̲a̲c̲k̲

result in IDE

Khalid
  • 41
  • 4
-3

On my IDE you can also use like the below Mentioned :

System.out.println("Underlined Text");
System.out.println("_______________")
Raymond Chenon
  • 11,482
  • 15
  • 77
  • 110