For the first problem (if I understand the problem) you may want to call trim after your first split on '|' eg String x = parts[pick].trim();
For the second problem you might have to elaborate to...