# java snipped simple if else

**URL:** <https://forum.knime.com/t/java-snipped-simple-if-else/26337>\
**Category:** KNIME Analytics Platform\
**Tags:** java\
**Created:** [August 26, 2020, 6:59am UTC](https://forum.knime.com/t/java-snipped-simple-if-else/26337 "2020-08-26T06:59:37Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![mlauber71](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mlauber71/32/73590_2.png) [@mlauber71](https://forum.knime.com/u/mlauber71)\
**Post date:** [August 26, 2020, 8:26am UTC](https://forum.knime.com/t/java-snipped-simple-if-else/26337/3 "2020-08-26T08:26:57Z")

</div>

I built this example from the previous one where you could use a combination of columns and Flow Variable in a simple Java Snippet. It might serve as another inspiration.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/a/c/ac19b76e737599b3ad0d05ab85a07af5aa8fa1c9.png)

> **[KNIME and Java - simple if then else - with some string conversion – mlauber71](https://hub.knime.com/mlauber71/spaces/Public/kn_example_java_simple_if_else_with_string_conversion~czsu2tjmQXob_Tys/current-state)**
>
> Demonstrates a simple if then else syntax in Java Snippet (Simple). Also doing a double to string conversion.

The code is like this:

```
// make the incoming Flow Variable into a Java variable
double v_input_factor;
v_input_factor = $${Dinput_factor}$$;

// convert the double Java variable into a string to use in the code
// https://www.journaldev.com/18380/java-convert-double-to-string
String v_input_factor_string = new StringBuilder().append(v_input_factor).toString();

// capture a possible problem with null values - if not the code might crash
if($var1$ == null) {
  return "missing";
}
else if ($var1$ > v_input_factor) {return "> " + v_input_factor_string;}
else if ($var1$ <= v_input_factor) {return "<= " + v_input_factor_string;}
else {return "something else";}

```

–  
Edit: [KNIME — Cases, Switches and Catching Errors](https://medium.com/low-code-for-advanced-data-science/knime-cases-switches-and-catching-errors-5ab748cbeaa3)

---

_[View the full topic](https://forum.knime.com/t/java-snipped-simple-if-else/26337)._
