int -> Integer new Integer(i);
Calculate the number of digits in a number: String.valueOf(i).length()
char -> string String.valueOf(char c)
Character.toLowerCase(char c) Character.toUpperCase(char c)
String s s.toLowerCase() s.toUpperCase()
sort ArrayList -> Collections.sort(array)
String -> int Integer.parseInt(s); Integer.valueOf(s);
int -> String String.valueOf(int i)
char -> int (int) char - '0'
char -> int : Character.getNumericValue(char).
Character.isLetter(char) Character.isDigit(char)
remove spaces s = s.replaceAll("\\s+", "");
s.split("/");
"+-*".indexOf(s.charAt(i))!=-1
Deque
A linear collection that supports element insertion and removal at both ends. The name deque is short for "double ended queue" and is usually pronounced "deck". Most Deque implementations place no fixed limits on the number of elements they may contain, but this interface supports capacity-restricted deques as well as those with no fixed size limit.
Queue Method | Equivalent Deque Method |
add(e) | addLast(e) |
offer(e) | offerLast(e) |
remove() | removeFirst() |
poll() | pollFirst() |
element() | getFirst() |
peek() | peekFirst() |
The following example illustrates how the String.split method can be used to break up a string into its basic tokens:
String[] result = "this is a test".split("\\s"); for (int x=0; x<result.length; x++) System.out.println(result[x]);
prints the following output:
this is a test
public StringTokenizer(String str, String delim, boolean returnDelims)
delim
argument are the delimiters for separating tokens.
If the returnDelims
flag is true
, then the delimiter characters are also returned as tokens. Each delimiter is returned as a string of length one. If the flag is false
, the delimiter characters are skipped and only serve as separators between tokens.
Note that if delim is null, this constructor does not throw an exception. However, trying to invoke other methods on the resulting StringTokenizer may result in a NullPointerException.
-
Parameters:
-
str
- a string to be parsed. -
delim
- the delimiters.returnDelims
- flag indicating whether to return the delimiters as tokens.
Substring(10):
for(int i = 0; i < s.length() - 9; i++){
String temp = s.substring(i, i + 10);