Example usage for java.lang Integer Integer

List of usage examples for java.lang Integer Integer

Introduction

In this page you can find the example usage for java.lang Integer Integer.

Prototype

@Deprecated(since = "9")
public Integer(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Integer object that represents the int value indicated by the String parameter.

Usage

From source file:Counter.java

public static void main(String[] args) {
    Map hm = new HashMap();
    for (int i = 0; i < 10000; i++) {
        // Produce a number between 0 and 20:
        Integer r = new Integer(rand.nextInt(20));
        if (hm.containsKey(r))
            ((Counter) hm.get(r)).i++;/*from   w  ww.  j a v a2  s .  c om*/
        else
            hm.put(r, new Counter());
    }
    System.out.println(hm);
}

From source file:MainClass.java

public static void main(String[] args) {
    if (args.length != 2) {
        String err = "Usage: KeyGeneratorApp algorithmName keySize";
        System.out.println(err);//from w  w w .  j ava2  s .  c  om
        System.exit(0);
    }
    int keySize = (new Integer(args[1])).intValue();
    SecretKey skey = null;
    KeyPair keys = null;
    String algorithm = args[0];

    try {
        KeyPairGenerator kpg = KeyPairGenerator.getInstance(algorithm);
        kpg.initialize(keySize);
        keys = kpg.genKeyPair();
    } catch (NoSuchAlgorithmException ex1) {
        try {
            KeyGenerator kg = KeyGenerator.getInstance(algorithm);
            kg.init(keySize);
            skey = kg.generateKey();
        } catch (NoSuchAlgorithmException ex2) {
            System.out.println("Algorithm not supported: " + algorithm);
            System.exit(0);

        }
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Boolean refBoolean = new Boolean(true);
    boolean bool = refBoolean.booleanValue();

    Byte refByte = new Byte((byte) 123);
    byte b = refByte.byteValue();

    Character refChar = new Character('x');
    char c = refChar.charValue();

    Short refShort = new Short((short) 123);
    short s = refShort.shortValue();

    Integer refInt = new Integer(123);
    int i = refInt.intValue();

    Long refLong = new Long(123L);
    long l = refLong.longValue();

    Float refFloat = new Float(12.3F);
    float f = refFloat.floatValue();

    Double refDouble = new Double(12.3D);
    double d = refDouble.doubleValue();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object o = new MyBean();
    // Get the value of prop2
    Expression expr = new Expression(o, "getProp2", new Object[0]);
    expr.execute();// w w  w.  ja v  a 2s . co m
    int i = ((Integer) expr.getValue()).intValue();

    // Set the value of prop2
    Statement stmt = new Statement(o, "setProp2", new Object[] { new Integer(123) });
    stmt.execute();
}

From source file:MultiArray1.java

public static void main(String args[]) {
    //       int array[][] = {{1,2,3}, {4,5,6}, {7,8,9}};
    //       int []array[] = {{1,2,3}, {4,5,6}, {7,8,9}};
    //       System.out.println(array[0][0]);
    //       System.out.println(array[1][0]);
    //       System.out.println(array[2][0]);
    //       System.out.println([0][0]array);
    //       System.out.println([1][0]array);
    //       System.out.println([2][0]array);
    Object events[][] = { { new Integer(1452), new String("Italy") },
            { new Integer(1472), new String("b.jpg") }, { new Integer(1483), new String("Hr") },
            { new Integer(1495), new String("Pte") }, { new Integer(1503), new String("m.jpg") },
            { new Integer(1519), new String("F") } };
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JSpinner spinner = new JSpinner();

    // Disable keyboard edits in the spinner
    JFormattedTextField tf = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField();
    tf.setEditable(false);//  ww  w.ja v a 2  s  .co m
    tf.setBackground(Color.white);

    // The value of the spinner can still be programmatically changed
    spinner.setValue(new Integer(100));
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    FileWriter fw = new FileWriter(args[0]);
    BufferedWriter bw = new BufferedWriter(fw);
    PrintWriter pw = new PrintWriter(bw, false);

    pw.println(true);//  w  w  w .jav  a 2 s. c o m
    pw.println('A');
    pw.println(500);
    pw.println(40000L);
    pw.println(45.67f);
    pw.println(45.67);
    pw.println("Hello");
    pw.println(new Integer("99"));

    pw.close();
}

From source file:LazySample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Lazy Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Integer fifteen = new Integer(15);
    Object lazyArgs[] = new Object[] { Color.GREEN, Boolean.TRUE, fifteen, fifteen };
    Object lazyDiamond = new UIDefaults.ProxyLazyValue("MyIcon", lazyArgs);
    UIManager.put("Tree.openIcon", lazyDiamond);

    JTree tree = new JTree();
    JScrollPane scrollPane = new JScrollPane(tree);

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(200, 200);// ww  w  .  j  a v a  2 s  .co m
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {

    try {//from  w w w.j a  va 2  s  .  c o m
        PrintWriter pw = new PrintWriter(System.out);

        // Experiment with some methods
        pw.println(true);
        pw.println('A');
        pw.println(500);
        pw.println(40000L);
        pw.println(45.67f);
        pw.println(45.67);
        pw.println("Hello");
        pw.println(new Integer("99"));

        // Close print writer
        pw.close();
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}

From source file:MemoryDemo.java

public static void main(String args[]) {
    Runtime r = Runtime.getRuntime();
    long mem1, mem2;
    Integer someints[] = new Integer[1000];

    System.out.println("Total memory is: " + r.totalMemory());

    mem1 = r.freeMemory();/*from  w w w.j  a  v a 2  s.c  o  m*/
    System.out.println("Initial free memory: " + mem1);
    r.gc();
    mem1 = r.freeMemory();
    System.out.println("Free memory after garbage collection: " + mem1);

    for (int i = 0; i < 1000; i++)
        someints[i] = new Integer(i); // allocate integers

    mem2 = r.freeMemory();
    System.out.println("Free memory after allocation: " + mem2);
    System.out.println("Memory used by allocation: " + (mem1 - mem2));

    for (int i = 0; i < 1000; i++)
        someints[i] = null;

    r.gc(); // request garbage collection

    mem2 = r.freeMemory();
    System.out.println("Free memory after collecting" + " discarded Integers: " + mem2);

}