Using Java 8 and higher, you can use the StringJoiner, a very clean and more flexible way (especially if you have a list as input instead of known set of variables a-e):
int a = 1;
int b = 0;
int c = 2;
int d = 2;
int e = 1;
List<Integer> values = Arrays.asList(a, b, c, d, e);
String result = values.stream().map(i -> i.toString()).collect(Collectors.joining());
System.out.println(result);
If you need a separator use:
String result = values.stream().map(i -> i.toString()).collect(Collectors.joining(","));
To get the following result:
1,0,2,2,1
Edit: as LuCio commented, the following code is shorter:
Stream.of(a, b, c, d, e).map(Object::toString).collect(Collectors.joining());
a
notb
, iffa==0
. – Parch