D
D
DDwrt1002021-02-10 11:04:02
Java
DDwrt100, 2021-02-10 11:04:02

How to optimize Java code when working with strings?

Good afternoon, there is a code that parses the log and normalizes it.

for (String a : rawToMassive) {
            if (a.contains("Var1:")) {
                a = a.replace("^Var1:", condition + ",");
                a = a + System.lineSeparator();
                out.append(a);

            }


I don't like that when I do an if , my String object is re-created twice. Is it possible to optimize it somehow?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-02-10
@DDwrt100

yes, use StringBuilder

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question