Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Ternary Operators in JAVA

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Location
    Pune
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Ternary Operators in JAVA

    So I'm learning Java on my own, and I'm curious how often you Developers out there with jobs use Ternary Operators instead of full conditional statements while at work or even in your hobby work.

    Thanks!

  2. #2
    Junior Member
    Join Date
    Sep 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Ternary Operators in JAVA

    Use ternary operations when you want your code to be readable.
    Using if/else, introduces boilerplate code, which can be hard to the eyes
    Also, when you need to return a or b based on a condition.

    One case to use if/else would be logging/debugging




    Java, Spring, Angular tips and tricks:
    https://codeinpackets.blogspot.com/
    Java, Spring, Angular tips and tricks:
    https://codeinpackets.blogspot.com/

Similar Threads

  1. Program using ternary operator.
    By OSWIN TOPNO in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 23rd, 2014, 09:33 AM
  2. Ternary operator
    By JRoberto in forum Other Programming Languages
    Replies: 8
    Last Post: December 29th, 2013, 06:33 PM
  3. Operators
    By Skybear in forum What's Wrong With My Code?
    Replies: 7
    Last Post: December 11th, 2012, 01:53 PM
  4. Processing of increment and decrement operators in Java
    By fredyeboah in forum What's Wrong With My Code?
    Replies: 9
    Last Post: June 22nd, 2012, 11:03 AM