How to check and get the value 0 or 1 of a string and save that number for that column?

0

I have to store the number 0 in a variable desc and 1 in the variable asc , if one of these values is found in string .

How do I do this?

package testes;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Ordenar {

public static void main(String[] args) {

      String desc = null;
      String asc = null;
      String coluna = null;
      List list = new ArrayList(); 
      String sampleString = "jrp_jasper.jrp_jas_nome|0;jrp_jasper.jrp_jas_sobrenome|1";

      String[] items = sampleString.split(";");
     // List<String> itemList = Arrays.asList(items);
      for(int i = 0; i < items.length; i++){

         if(sampleString.charAt(i) == '0'){
             desc = "0";
             System.out.println(desc);
         }else{
             asc = "1";
             System.out.println(asc);
         }

         coluna = items[i].replaceAll("[|01]", "");
         Map map = new HashMap();
         map.put(coluna, asc);
         list.add(coluna);

         // ....
    
asked by anonymous 03.08.2016 / 19:05

1 answer

5

Change the validation of your if , using contains on an item in the string vector items :

if(items[i].contains("0")){
    desc = "0";
    System.out.println(desc);
}else if((items[i].contains("1"))){
    asc = "1";
    System.out.println(asc);
}
    
03.08.2016 / 19:15