0
I have to keep the number 0
in a variable desc
and 1
in the variable asc
, if one of these values is found in the string.
How do I do it?
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);
// ....
Use equals and not equal sign when comparing strings. Another thing, the 0 and 1 are not separated by point and comma, the split will not locate them. Not to mention that your loop is on top of the list separated by period and comma, the if won’t run through all the chars.
– user28595
Give me a better idea? Please...
– Aline
The best way to compare Java Strings is to use . equals() "Stringquevcquerto compare.equals(Stringqueseracomparative)".
– Edumachdo