Toán tử Ternary trong Java là gì? Cách dùng thay thế if-else & switch
2 phút đọc12/09/2025
Về tác giả
I’m passionate about web development and sharing my insights through articles, with over 8 years of experience. I hope these sharings inspire you and help build a strong web development community.
@#@
Tôi đam mê phát triển web và chia sẻ những hiểu biết của mình thông qua các bài viết, với hơn 8 năm kinh nghiệm. Tôi hy vọng những chia sẻ này sẽ truyền cảm hứng cho các bạn và giúp xây dựng một cộng đồng phát triển web mạnh mẽ.
Cập nhật thông tin mới nhấtNhận các thông tin mới nhất về mối đe dọa, báo cáo an ninh mạng từ CyStack về hòm thư điện tử của bạn
{"success":true,"head":"<title>Toán tử Ternary trong Java là gì? Cách dùng thay thế if-else & switch - CyStack Tutorial</title>\n<meta name=\"description\" content=\"Toán tử Ternary trong Java là toán tử điều kiện duy nhất sử dụng ba toán hạng. Nó là một cách viết thay thế ngắn gọn cho câu lệnh if-then-else\"/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-video-preview:-1, max-image-preview:large\"/>\n<link rel=\"canonical\" href=\"https://blog.cystack.org/tutorial/vi/2025/09/12/toan-tu-ternary-trong-java-la-gi-cach-dung-thay-the-if-else-switch/\" />\n<meta property=\"og:locale\" content=\"en_US\" />\n<meta property=\"og:type\" content=\"article\" />\n<meta property=\"og:title\" content=\"Toán tử Ternary trong Java là gì? Cách dùng thay thế if-else & switch - CyStack Tutorial\" />\n<meta property=\"og:description\" content=\"Toán tử Ternary trong Java là toán tử điều kiện duy nhất sử dụng ba toán hạng. Nó là một cách viết thay thế ngắn gọn cho câu lệnh if-then-else\" />\n<meta property=\"og:url\" content=\"https://blog.cystack.org/tutorial/vi/2025/09/12/toan-tu-ternary-trong-java-la-gi-cach-dung-thay-the-if-else-switch/\" />\n<meta property=\"og:site_name\" content=\"CyStack Tutorial\" />\n<meta property=\"article:tag\" content=\"vi\" />\n<meta property=\"article:section\" content=\"Java\" />\n<meta property=\"og:updated_time\" content=\"2026-08-03T17:19:55+07:00\" />\n<meta property=\"og:image\" content=\"https://s2.cystack.net/tutorial/12104608/Frame-10-20.jpg\" />\n<meta property=\"og:image:secure_url\" content=\"https://s2.cystack.net/tutorial/12104608/Frame-10-20.jpg\" />\n<meta property=\"og:image:width\" content=\"1200\" />\n<meta property=\"og:image:height\" content=\"630\" />\n<meta property=\"og:image:alt\" content=\"Toán tử Ternary trong Java\" />\n<meta property=\"og:image:type\" content=\"image/jpeg\" />\n<meta property=\"article:published_time\" content=\"2025-09-12T10:46:42+07:00\" />\n<meta property=\"article:modified_time\" content=\"2026-08-03T17:19:55+07:00\" />\n<meta name=\"twitter:card\" content=\"summary_large_image\" />\n<meta name=\"twitter:title\" content=\"Toán tử Ternary trong Java là gì? Cách dùng thay thế if-else & switch - CyStack Tutorial\" />\n<meta name=\"twitter:description\" content=\"Toán tử Ternary trong Java là toán tử điều kiện duy nhất sử dụng ba toán hạng. Nó là một cách viết thay thế ngắn gọn cho câu lệnh if-then-else\" />\n<meta name=\"twitter:image\" content=\"https://s2.cystack.net/tutorial/12104608/Frame-10-20.jpg\" />\n<meta name=\"twitter:label1\" content=\"Written by\" />\n<meta name=\"twitter:data1\" content=\"Bao Tran\" />\n<meta name=\"twitter:label2\" content=\"Time to read\" />\n<meta name=\"twitter:data2\" content=\"1 minute\" />\n<script type=\"application/ld+json\" class=\"rank-math-schema\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https://blog.cystack.org/tutorial/#person\",\"name\":\"CyStack Tutorial\"},{\"@type\":\"WebSite\",\"@id\":\"https://blog.cystack.org/tutorial/#website\",\"url\":\"https://blog.cystack.org/tutorial\",\"name\":\"CyStack Tutorial\",\"publisher\":{\"@id\":\"https://blog.cystack.org/tutorial/#person\"},\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https://s2.cystack.net/tutorial/12104608/Frame-10-20.jpg\",\"url\":\"https://s2.cystack.net/tutorial/12104608/Frame-10-20.jpg\",\"width\":\"1200\",\"height\":\"630\",\"caption\":\"To\\u00e1n t\\u1eed Ternary trong Java\",\"inLanguage\":\"en-US\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://blog.cystack.org/tutorial/vi/2025/09/12/toan-tu-ternary-trong-java-la-gi-cach-dung-thay-the-if-else-switch/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":\"1\",\"item\":{\"@id\":\"https://blog.cystack.org/tutorial\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":\"2\",\"item\":{\"@id\":\"https://blog.cystack.org/tutorial/vi/category/java/\",\"name\":\"Java\"}},{\"@type\":\"ListItem\",\"position\":\"3\",\"item\":{\"@id\":\"https://blog.cystack.org/tutorial/vi/2025/09/12/toan-tu-ternary-trong-java-la-gi-cach-dung-thay-the-if-else-switch/\",\"name\":\"To\\u00e1n t\\u1eed Ternary trong Java l\\u00e0 g\\u00ec? C\\u00e1ch d\\u00f9ng thay th\\u1ebf if-else & switch\"}}]},{\"@type\":\"WebPage\",\"@id\":\"https://blog.cystack.org/tutorial/vi/2025/09/12/toan-tu-ternary-trong-java-la-gi-cach-dung-thay-the-if-else-switch/#webpage\",\"url\":\"https://blog.cystack.org/tutorial/vi/2025/09/12/toan-tu-ternary-trong-java-la-gi-cach-dung-thay-the-if-else-switch/\",\"name\":\"To\\u00e1n t\\u1eed Ternary trong Java l\\u00e0 g\\u00ec? C\\u00e1ch d\\u00f9ng thay th\\u1ebf if-else & switch - CyStack Tutorial\",\"datePublished\":\"2025-09-12T10:46:42+07:00\",\"dateModified\":\"2026-08-03T17:19:55+07:00\",\"isPartOf\":{\"@id\":\"https://blog.cystack.org/tutorial/#website\"},\"primaryImageOfPage\":{\"@id\":\"https://s2.cystack.net/tutorial/12104608/Frame-10-20.jpg\"},\"inLanguage\":\"en-US\",\"breadcrumb\":{\"@id\":\"https://blog.cystack.org/tutorial/vi/2025/09/12/toan-tu-ternary-trong-java-la-gi-cach-dung-thay-the-if-else-switch/#breadcrumb\"}},{\"@type\":\"Person\",\"@id\":\"https://blog.cystack.org/tutorial/author/baotran/\",\"name\":\"Bao Tran\",\"url\":\"https://blog.cystack.org/tutorial/author/baotran/\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https://secure.gravatar.com/avatar/0cdd33c02ec4a531fcf557b9c1ccc276df0c69031b2382c959bcf335248e840c?s=96&d=mm&r=g\",\"url\":\"https://secure.gravatar.com/avatar/0cdd33c02ec4a531fcf557b9c1ccc276df0c69031b2382c959bcf335248e840c?s=96&d=mm&r=g\",\"caption\":\"Bao Tran\",\"inLanguage\":\"en-US\"}},{\"@type\":\"BlogPosting\",\"headline\":\"To\\u00e1n t\\u1eed Ternary trong Java l\\u00e0 g\\u00ec? C\\u00e1ch d\\u00f9ng thay th\\u1ebf if-else & switch - CyStack Tutorial\",\"keywords\":\"To\\u00e1n t\\u1eed Ternary trong Java,To\\u00e1n t\\u1eed Ternary,Ternary\",\"datePublished\":\"2025-09-12T10:46:42+07:00\",\"dateModified\":\"2026-08-03T17:19:55+07:00\",\"articleSection\":\"Java\",\"author\":{\"@id\":\"https://blog.cystack.org/tutorial/author/baotran/\",\"name\":\"Bao Tran\"},\"publisher\":{\"@id\":\"https://blog.cystack.org/tutorial/#person\"},\"description\":\"To\\u00e1n t\\u1eed Ternary trong Java l\\u00e0 to\\u00e1n t\\u1eed \\u0111i\\u1ec1u ki\\u1ec7n duy nh\\u1ea5t s\\u1eed d\\u1ee5ng ba to\\u00e1n h\\u1ea1ng. N\\u00f3 l\\u00e0 m\\u1ed9t c\\u00e1ch vi\\u1ebft thay th\\u1ebf ng\\u1eafn g\\u1ecdn cho c\\u00e2u l\\u1ec7nh if-then-else\",\"name\":\"To\\u00e1n t\\u1eed Ternary trong Java l\\u00e0 g\\u00ec? C\\u00e1ch d\\u00f9ng thay th\\u1ebf if-else & switch - CyStack Tutorial\",\"@id\":\"https://blog.cystack.org/tutorial/vi/2025/09/12/toan-tu-ternary-trong-java-la-gi-cach-dung-thay-the-if-else-switch/#richSnippet\",\"isPartOf\":{\"@id\":\"https://blog.cystack.org/tutorial/vi/2025/09/12/toan-tu-ternary-trong-java-la-gi-cach-dung-thay-the-if-else-switch/#webpage\"},\"image\":{\"@id\":\"https://s2.cystack.net/tutorial/12104608/Frame-10-20.jpg\"},\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https://blog.cystack.org/tutorial/vi/2025/09/12/toan-tu-ternary-trong-java-la-gi-cach-dung-thay-the-if-else-switch/#webpage\"}}]}</script>\n"}