Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
Java Filter string values separated by comma

Below is the string of values separated by commas. Need to filter each values and append them with specific values.

String values - Hello, MyName, Is, XYZ

Above is the string that i am sending through an API

What i want is - How to add (_true) this string value to each element on above String Values. That also to few String values that i am checking with some specific condition

So that it should be like below in that API call which is sent to FrontEnd.

Hello(_true), MyName, Is, XYZ(_true)

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

public static String StringAppenderWithLogic(String given, String del) {
    return String.join(del, Arrays.stream(given.split(del)).
            map(p -> {
                //put any logic specific to your requirement
                if (p.trim().startsWith("H") || p.trim().startsWith("X")) {
                    p = p + "(_true)";

                }
                return p;
            }).collect(Collectors.toList()));
}
about 4 years ago · Juan Pablo Isaza Relatório

0

You can try this

import java.util.*;
import java.util.stream.Collectors;

public class Main
{
    public static void main(String[] args) {
        String apiOutput = "Hello, MyName, Is, XYZ";
        
        List<String> s = List.of(apiOutput.split(", ")).stream()
            .map(Main::stringController)
            .collect(Collectors.toList());
        String result = String.join(", ", s);
        
        System.out.println(result);
        
    }
    
    private static String stringController(String in){
        if(hasMatchCondition(in)){
            return in + "(_true)";
        }
        return in;
    }
    
    private static boolean hasMatchedCondition(String in){
        //place your logic here
        
        //[START] exemple
        if(in.length() == 5 || in.length() == 3)
            return true;
        return false;
        //[END] exemple
    }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda