OK see I assume split is the only chance; now: what's the best?
way1 or way2? I would prefer a stack but I'm not able to convert the split string in a stack<String>Code:StringBuilder sb = new StringBuilder(); for (int ii=0; ii < 1000; ii++ ){ sb.append("home" + "."); } sb.replace(sb.length()-1, sb.length()-1, ""); String[] sp = sb.toString().split("[.]"); //way 1 for (int i=0; i < sp.length && i<=2; i++) System.out.println ( sp[sp.length-1-i] ); //way2 List<String> list = new ArrayList<String>( Arrays.asList(sb.toString().split("[.]") )); for (int q=0; q < 3; q++) { System.out.println( list.remove( list.size() -1 ) ); }
thanks




Reply With Quote