|
Jun 11
|
You can tell the parseInt() method what base number system is used by the String that is being parsed.
String hex = "01001101"; int n = Integer.parseInt(hex, 2);
|
|
You can tell the parseInt() method what base number system is used by the String that is being parsed. String hex = "01001101"; int n = Integer.parseInt(hex, 2);
Often you need to read a file line by line. Alternatively sometimes you want to read text word by word (for example to count the occurrence of different words). The Scanner classes next() method can be used for this as shown in the following example.
Scanner input = new Scanner(file);
while(input.hasNext()) {
String word = input.next();
}
The URL class can be used to parse a URL and retrieve the components such as host name String urlstring = "http://www.objects.com.au/services/sherpa.html" URL url = new URL(urlstring}; String host = url.getHost(); // returns "www.objects.com.au" |
|
Recent Comments