Tokenizers:
- StringTokenizer tokenizer = new StringTokenizer(“Example String Here”, delimiter (blank if space));
- while(tokenizer.hasMoreElements()){
- Integer i = Integer.parseInt(tokenizer.nextElement().toString());
- }
Substring:
- String full = “Full Text”;
- String sub = full.substring(5,9);
- System.out.println(“Will print the word ‘Text’: ” + sub);
Split:
- String full = “This is the full text”;
- String[] = full.split(” “); //or regular expression
- string.trim();
Character At:
- char c = string.charAt(7);
Replace:
- String s = “Hello”;
- s.replace(‘H’, ‘J’);//turns Hello to Jello
- s = “Hello”;
- s.replace(“Hello”, “Jello”);//also turns to Jello
Character Array:
- char[] cha = new char[str.length()];
- for(int i=0;i<str.length();i++){
- cha[i] = str.charAt(i);
- }
- //toString for printout
From the blog shatos by shatos and used with permission of the author. All other rights reserved by the author.