LoginSignup
0
0

String.formatでjson文字列作成

Posted at
public class Main {
    public static void main(String[] args) throws Exception {
        // Sample data
        String name = "John";
        int age = 30;
        String city = "New York";

        // Format JSON string using String.format
        String jsonString = String.format("{\"name\":\"%s\", \"age\":%d, \"city\":\"%s\"}", name, age, city);

        // Print formatted JSON string
        System.out.println(jsonString);
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0