I
I
insomnia772015-11-03 15:53:17
Java
insomnia77, 2015-11-03 15:53:17

Is it possible to simplify this code in Java (working with a string)?

Good afternoon. As an input to the automated test, I submit data arrays (String), which can be in English, Russian or null. I get a very long string like:

String JobPlace = ((start.JobPlace.length > 1 ? start.JobPlace[cc] : start.JobPlace[0]) == null) ? null : new String(((start.JobPlace.length > 1) ? start.JobPlace[cc] : start.JobPlace[0]).getBytes(), StandardCharsets.UTF_8);

Is it possible to optimize/reduce it?
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evhen, 2015-11-03
@insomnia77

  1. replace conditions with if/else constructs;
    And wakes up OK

Z
Zelimkhan Beltoev, 2015-11-03
@Beltoev

String JobPlace = start.JobPlace.length > 1 ? start.JobPlace[cc] : start.JobPlace[0];
if (JobPlace != null)
    JobPlace = new String(JobPlace.getBytes(), StandardCharsets.UTF_8);

O
Oleg Gamega, 2015-11-03
@gadfi

Personally, it is not convenient for me to read this, this form of recording does not give a performance gain, but it reads worse.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question