Recent Notes
Displaying keyword search results 91 - 100
Created by alfa on April 11, 2011 21:40:51
Last update: April 11, 2011 21:40:51
Integer.bitCount counts the number of one-bits in the two's complement binary representation of the specified int value. Example code:
public class CountOnes {
public static void...
For long , there's Long.bitCount()
Created by alfa on April 11, 2011 21:32:52
Last update: April 11, 2011 21:32:52
Some methods to convert int to String in Java:
String concatenation
String s = "" + 1234;
Using Integer object
String s = Integer.toString(1234);
Using String object
String s = String.valueOf(1234);
Created by alfa on April 11, 2011 21:28:04
Last update: April 11, 2011 21:28:24
Some methods to convert Java String to int:
To primitive int:
int i = Integer.parseInt("11111");
To Integer object:
Integer i = new Integer("1234");
// to prim...
To Integer object:
Integer i = Integer.valueOf("44321");
Created by alfa on April 11, 2011 21:17:11
Last update: April 11, 2011 21:17:11
Some methods to create an array in Java:
With literal initialization.
// array of strings
String[] dogs = { "Chihuah...
With array constructor (array allocated by not the elements).
// create a byte array
byte[] buffer = new byte...
Anonymous array to be used as a parameter in method invocation
String.format("Hello %s, %s, %s!", new Object[] { ...
Created by alfa on April 08, 2011 14:42:23
Last update: April 08, 2011 14:42:23
public class TestInnerClass {
private stati...
Created by alfa on April 08, 2011 14:14:46
Last update: April 08, 2011 14:26:13
It's a lot easier to use swing JOptionPane to present a dialog. But if plain awt is what you want, this is the code. A Dialog is a Window object, so you paint it just like you would for a window.
import java.awt.*;
import java.awt.event.*;
...
Created by alfa on April 08, 2011 12:33:08
Last update: April 08, 2011 12:33:08
This example captures the screen of the current Java application window, instead of the full screen.
import java.io.*;
import java.awt.*;
import ...
Created by alfa on April 04, 2011 18:09:43
Last update: April 08, 2011 12:27:11
import java.awt.Graphics;
import java.awt.event...
Created by nogeek on April 07, 2011 21:07:55
Last update: April 07, 2011 21:07:55
You can use the javax.xml.transform.Transformer class to "transform" an XML stream (string in this case) to a DOM tree - effectively parsing the XML string.
import java.io.*;
import javax.xml.transform.Tr...
Created by nogeek on April 07, 2011 20:54:17
Last update: April 07, 2011 20:54:17
Use javax.xml.parsers.DocumentBuilder to parse xml. DocumentBuilder.parse() takes:
java.io.File
org.xml.sax.InputSource
java.io.InputStream
java.lang.String as a URI to an XML document
Example code:
import java.io.*;
import javax.xml.parsers.Docu...