package demo.combobox.simple_combobox;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ShirtData {
private static List<String> colors = new ArrayList<String>();
private static List<String> sizes = new ArrayList<String>();
static{
colors.add("blue");
colors.add("black");
colors.add("white");
sizes.add("small");
sizes.add("medium");
sizes.add("large");
}
public static final List<String> getColors() {
return new ArrayList<String>(colors);
}
public static final List<String> getSizes() {
return new ArrayList<String>(sizes);
}
}
How to cast an Object to an int in java?
http://stackoverflow.com/questions/3661413/how-to-cast-an-object-to-an-int-in-java
If you're sure that this object is an Integer
:
int i = (Integer) object;
Or, starting from Java 7, you can equivalently write:
int i = (int) object;
Beware, it can throw a ClassCastException
if your object isn't an Integer
and aNullPointerException
if your object is null
.
This way you assume that your Object is an Integer (the wrapped int) and you unbox it into an int.
int
is a primitive so it can't be stored as an Object
, the only way is to have an int
considered/boxed as an Integer
then stored as an Object
.
If your object is a String
, then you can use the Integer.valueOf()
method to convert it into a simple int :
int i = Integer.valueOf((String) object);
It can throw a NumberFormatException
if your object isn't really a String
with an integer as content.
Java Inner class example
import java.util.*;
public class SampleVM {
private List<MyData> names = new ArrayList<MyData>();
public SampleVM() {
names.add(new MyData("name 1",true));
names.add(new MyData("name 2",false));
names.add(new MyData("name 3",false));
names.add(new MyData("name 4",false));
names.add(new MyData("name 5",false));
}
public List<MyData> getNames() {
return names;
}
public class MyData{
String name;
boolean open;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isOpen() {
return open;
}
public void setOpen(boolean open) {
this.open = open;
}
public MyData(String name, boolean open) {
super();
this.name = name;
this.open = open;
}
}
}
Hibernate Where in clause to Delete multiple items @Override
public void deletePracticeAppMenu(List<Long> prAppMenuIDs, Long practiceID) {
String query = "delete from PracticeAppMenu where PrAppMenuID in (:appMenuIDs) and practiceID = :pracid ";
Query q = getCurrentSession().createQuery(query);
q.setParameterList("appMenuIDs", prAppMenuIDs);
q.setParameter("pracid", practiceID);
q.executeUpdate();
}