[JAVA] Notation to put a variable in a string

I originally touched programming in Ruby and wrote CGI in eRuby, so I used to put variables enclosed in {} in strings.

str1 = "Hello"
str2 = "World!"
print "#{str1}, #{str2}\n"

If you try to write this in C #, it will look like this.

var str1 = "Hello";
var str2 = "World!";
Console.Write($"{str1}, {str2}\n") ;

It seems that you can write it like this with another solution.

var str1 = "Hello";
var str2 = "World!";
Console.Write("{0}, {1}\n", str1, str2);

By the way, I recently started Java, and it seems that Java is written like this.

var str1 = "Hello";
var str2 = "World!";
System.out.printf("%s, %s\n", str1, str2);

It's similar to the C # pattern in HelloWorldAlt.cs that I wrote later. Java is the most difficult to understand, so I thought I'd write the latter notation, which is close to Java notation, when writing in C # in the future.

Recommended Posts

Notation to put a variable in a string
Convert a Java byte array to a string in hexadecimal notation
[Ruby] I want to put an array in a variable. I want to convert to an array
Convert to a tag to URL string in Rails
Code to escape a JSON string in Java
Pass a variable to Scope.
How to change a string in an array to a number in Ruby
How to store a string from ArrayList to String in Java (Personal)
I tried to convert a string to a LocalDate type in Java
How to store the information entered in textarea in a variable in the method
How to insert a video in Rails
Steps to set a favicon in Rails
Split a string with ". (Dot)" in Java
How to publish a library in jCenter
StackOverflowError to String causes a circular reference
How to get the current date as a string in yyyyMMdd format
How to change the value of a variable at a breakpoint in intelliJ
I tried to easily put CentOS-7 in a PC that I no longer need
Two ways to start a thread in Java + @
[Android] How to convert a character string to resourceId
I want to use arrow notation in Ruby
How to display a web page in Java
How to check if an instance variable is defined in a Ruby class
Try to create a bulletin board in Java
Convert a string to a character-by-character array with swift
[Spring Boot] How to get properties dynamically from a string contained in a URL
I want to simply write a repeating string
How to run a djUnit task in Ant
How to add a classpath in Spring Boot
How to create a theme in Liferay 7 / DXP
How to implement a like feature in Rails
How to easily create a pull-down in Rails
[Ruby] How to generate a random alphabet string
How to make a follow function in Rails
How to write Java String # getBytes in Kotlin?
How to automatically generate a constructor in Eclipse
I want to find the MD5 checksum of a file in Java and get the result as a string in hexadecimal notation.
How to use a structure with variable length array or bit field in Ruby-FFI
How to clear all data in a particular table
How to create a Java environment in just 3 seconds
Sample code to convert List to List <String> in Java Stream
Change date and time to Japanese notation in Rails
How to create a Spring Boot project in IntelliJ
Throw raw SQL to a read replica in Rails
I tried to create a Clova skill in Java
How to create a data URI (base64) in Java
How to launch another command in a Ruby program
I tried to make a login function in Java
How to display a browser preview in VS Code
[How to insert a video in haml with Rails]
How to write a date comparison search in Rails
I want to define a function in Rails Console
How to store Rakuten API data in a table
How to mock a super method call in PowerMock
[Java] How to erase a specific character from a character string
How to convert A to a and a to A using AND and OR in Java
Ruby Regular Expression Extracts from a specific string to a string
How to convert a file to a byte array in Java
Try to solve a restricted FizzBuzz problem in Java
[Rails 6] How to set a background image in Rails [CSS]
I want to click a GoogleMap pin in RSpec