//creating Item data object Item item = new Item(); item.setId(2); item.setName("Foo"); item.setPrice(200); ..... JAXBContext context = JAXBContext.newInstance(item.getClass()); Marshaller marshaller = context.createMarshaller(); marshaller.marshal(item, new FileWriter("item.xml")); //I want to save the output file to item.xml
public void postFlush(Iterator iterator) { for(; iterator.hasNext();) { if(!(iterator.next() instanceof Item)){ //<<<<< You verify if you are saving Item or //other objects, if saving Item, skip this block. Session tempSession = HibernateUtil.hibernateTemplateLog .getSessionFactory().openSession(); try { Item item = new Item(); item.setName("anyItem"); item.setValue("anyValue"); tempSession.save(item); tempSession.flush(); } finally { tempSession.close(); } } } } }
NodeList idlist = doc.getElementsByTagName(KEY_ID); NodeList namelist = doc.getElementsByTagName(KEY_NAME); NodeList costlist = doc.getElementsByTagName(KEY_COST); NodeList desclist = doc.getElementsByTagName(KEY_DESC); for (int i=0; i<idlist.getLength(); i++) { Item item = new Item(); item.setCost(costlist.item(i).getTextContent()); item.setDescription(desclist.item(i).getTextContent()); item.setName(namelist.item(i).getTextContent()); itemarray.add(item); }
Item itemObject = new Item (); System.out.println("Enter an item you want to add to your list "+ x); itemObject.setName(keyboard.next()); System.out.println("Enter a price "+x); itemObject.setPrice(keyboard.nextDouble()); System.out.println("Enter the priority of the item "+x); itemObject.setPriority(keyboard.nextInt()); list[x] = itemObject;
public List<Item> list() throws SQLException { Connection connection = null; Statement statement = null; ResultSet resultSet = null; List<Item> items = new ArrayList<Item>(); try { connection = database.getConnection(); statement = connection.createStatement(); resultSet = statement.executeQuery(SQL_LIST); while (resultSet.next()) { Item item = new Item(); item.setId(resultSet.getLong("id")); item.setName(resultSet.getString("name")); // ... items.add(item); } } finally { if (resultSet != null) try { resultSet.close(); } catch (SQLException logOrIgnore) {} if (statement != null) try { statement.close(); } catch (SQLException logOrIgnore) {} if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {} } return items; }
ArrayList<Item> items = new ArrayList<>(); Cursor cursor = //make a call to database if (cursor.moveToFirst()) { Item item; for (int i = 0; i < cursor.getCount(); i++) { item = new Item(); item.setName("read data from cursor and add it here"); item.setMeasurment("read data from cursor and add it here"); item.setUnit("read data from cursor and add it here"); myModels.add(item); if (!cursor.moveToNext()) { break; } } }
int idIndex = cursor.getColumnIndex(items_id); int nameIndex = cursor.getColumnIndex(items_item_name); //etc. while (cursor.moveToNext()) { Item dbitems = new Item(); dbitems.setID(cursor.getLong(idIndex)); dbitems.setName(cursor.getString(nameIndex)); ... itemList.add(dbitems); }
item.setName("Laura" + i); mItemArrayList.add(item);
@Override protected Void doInBackground(Void... params) { // TODO Auto-generated method stub // Creating JSON Parser instance JSONObjParser jParser = new JSONObjParser(); // getting JSON string from URL JSONArray json = jParser.getJSONFromUrl(url); // getting JSON string from URL JSONArray json1 = jParser.getJSONFromUrl(url1); // assume json's length is the same as json1's try { for (int i = 0; i < json1.length(); i++) { JSONObject c = json1.getJSONObject(i); Item item = new Item(); // Storing each json item in variable int id = c.getInt("_id"); String TIME = c.getString("RestaurantTime"); item.setTime(TIME); c = json.getJSONObject(i); // Storing each json item in variable String NAME=c.getString("restaurantNAME"); item.setName(NAME); yourData.add(item); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
public class TestPaper { public static void main(String[] args) { Item item; Item[] itemTable = new Item[7]; ArrayList<Item> itemlist = new ArrayList<>(); for (int i = 0; i < 7; i++) { item = new Item(); //set value item.setName("item1"); item.setPrice(200); //store the object to a table or an arraylist itemTable[i] = item; itemlist.add(item); } for (Item temp : itemTable) { System.out.println(temp.toString()); } } }
Item mItem = new Item(); // <-- instantiate a new Item. mItem.setCode("101"); mItem.setName("Hammer"); mItem.setQty(10); sBarang.add(mItem); // <-- add it to your List<Item>.
public class ItemAdapter extends XmlAdapter<ItemProxy, Item> { @Override public ItemProxy marshal( Item v ) throws Exception { ItemProxy proxy = new ItemProxy(); proxy.setCategory( v.getCategory().getCode() ); proxy.setSubcategory( v.getSubCategory().getCode() ); proxy.setName( v.getName() ); return proxy; } @Override public Item unmarshal( ItemProxy v ) throws Exception { Item item = new Item(); Category category = new Category( v.getCategory() ); SubCategory subCategory = new SubCategory( v.getSubcategory(), category ); item.setName( v.getName() ); item.setCategory( category ); item.setSubCategory( subCategory ); return item; } }
Item itm = new Item(); itm.setName("NewItem"); Category cat = new Category(); cat.setName("NewCategory"); itm.getCategoryCollection().add(cat); cat.getItemCollection().add(itm);
Item item = new Item(); item.setName(item.getString("name")); item.setCategory(item.getString("category")); item.setID(item.getString("id")); List<Item> itemList= items.get(item.getCategotry()); if (itemList ==null){ itemList = new ArrayList<>(); items.put(item.getCategotry(),itemList); } itemList.add(item);