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:Main.java

public static void main(String[] argv) throws Exception {
    IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>();

    Object o1 = new Integer(123);
    Object o2 = new Integer(123);
    objMap.put(o1, "first");
    objMap.put(o2, "from java2s.com");

    Object v1 = objMap.get(o1);//from w w  w .ja v  a  2  s  .  c  o m
    System.out.println(v1);
    Object v2 = objMap.get(o2);
    System.out.println(v2);

    System.out.println(objMap.isEmpty());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>();

    Object o1 = new Integer(123);
    Object o2 = new Integer(123);
    objMap.put(o1, "first");
    objMap.put(o2, "from java2s.com");

    Object v1 = objMap.get(o1);/*from   www  . jav  a  2  s.  c  o  m*/
    System.out.println(v1);
    Object v2 = objMap.get(o2);
    System.out.println(v2);

    boolean isavailable = objMap.containsValue("first");

    System.out.println(isavailable);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>();

    Object o1 = new Integer(123);
    Object o2 = new Integer(123);
    objMap.put(o1, "first");
    objMap.put(o2, "from java2s.com");

    Object v1 = objMap.get(o1);/*from  w  w  w.ja v a 2  s  . c o m*/
    System.out.println(v1);
    Object v2 = objMap.get(o2);
    System.out.println(v2);

    // check if key 3 exists
    boolean isavailable = objMap.containsKey(o1);

    System.out.println(isavailable);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>();

    Object o1 = new Integer(123);
    Object o2 = new Integer(123);
    objMap.put(o1, "first");
    objMap.put(o2, "from java2s.com");

    Object v1 = objMap.get(o1);/* w ww.  j  a v a 2  s.c o  m*/
    System.out.println(v1);
    Object v2 = objMap.get(o2);
    System.out.println(v2);

    objMap.clear();

    System.out.println("Map content after clear: " + objMap);

}

From source file:HashSetExample.java

public static void main(String[] args) {
    Set<Integer> set = new HashSet<Integer>();

    set.add(new Integer(1));
    set.add(new Integer(2));
    set.add(new Integer(3));
    set.add(new Integer(4));
    set.add(new Integer(5));
    set.add(new Integer(6));
    set.add(new Integer(7));
    set.add(new Integer(8));
    set.add(new Integer(9));
    set.add(new Integer(10));

    // Use iterator to display the vsetes
    System.out.println("HashSet Before: ");
    for (Iterator i = set.iterator(); i.hasNext();) {
        Integer integer = (Integer) i.next();
        System.out.println(integer);
    }//from  w w w  .  java2  s.co m

    // Remove the integer 6
    System.out.println("\nRemove integer 6");
    set.remove(new Integer(6));

    // Use iterator to display the vsetes
    System.out.println("\nHashSet After: ");
    for (Iterator i = set.iterator(); i.hasNext();) {
        Integer integer = (Integer) i.next();
        System.out.println(integer);
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    IdentityHashMap<Object, Object> objMap = new IdentityHashMap<Object, Object>();

    Object o1 = new Integer(123);
    Object o2 = new Integer(123);
    objMap.put(o1, "first");
    objMap.put(o2, "from java2s.com");

    Object v1 = objMap.get(o1);//from   w ww  . ja  va2  s. c  o  m
    System.out.println(v1);
    Object v2 = objMap.get(o2);
    System.out.println(v2);

    // clone the map
    IdentityHashMap ihmapclone = (IdentityHashMap) objMap.clone();

    System.out.println("Cloned map content: " + ihmapclone);

}

From source file:Main.java

public static final void main(final String[] args) throws Exception {
    SomeNumbers obj = new SomeNumbers();
    System.out.println("Before: " + obj);

    final Integer value = new Integer(0);
    Field[] fields = obj.getClass().getFields();
    for (int idx = 0; idx < fields.length; idx++) {
        if (fields[idx].getType() == int.class) {
            fields[idx].set(obj, value);
        }/*from   w  w  w.ja v a 2s.  co  m*/
    }

    System.out.println("After: " + obj);
}

From source file:Main.java

public static void main(String[] args) {
    LinkedHashSet<Integer> lhashSet = new LinkedHashSet<Integer>();

    System.out.println("Size of LinkedHashSet : " + lhashSet.size());
    lhashSet.add(new Integer("1"));
    lhashSet.add(new Integer("2"));
    lhashSet.add(new Integer("3"));

    System.out.println(lhashSet.size());

    lhashSet.remove(new Integer("1"));

    System.out.println(lhashSet.size());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    List<Integer> list = new ArrayList<Integer>();

    for (int i = 1; i <= 12; i++)
        list.add(new Integer(i));

    Collections.shuffle(list);/*  ww  w .  ja  v  a 2  s  .com*/
    System.out.println(list);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Hashtable h = new Hashtable();
    h.put("string", "AAA");
    h.put("int", new Integer(26));
    h.put("double", new Double(Math.PI));

    FileOutputStream fileOut = new FileOutputStream("hashtable.ser");
    ObjectOutputStream out = new ObjectOutputStream(fileOut);
    out.writeObject(h);/* ww w  . j  a  v  a 2  s .  c o  m*/

    FileInputStream fileIn = new FileInputStream("h.ser");
    ObjectInputStream in = new ObjectInputStream(fileIn);
    Hashtable h = (Hashtable) in.readObject();
    System.out.println(h.toString());
}