วันพฤหัสบดีที่ 31 กรกฎาคม พ.ศ. 2557

Java java.lang Boolean booleanValue()

Java java.lang Boolean booleanValue()

Description Of Boolean: booleanValue()


The java.lang.Boolean.booleanValue() returns the value of this Boolean object as a boolean primitive

Boolean.booleanValue() method returns the primitive boolean value of this object.

Code Example Java Boolean

public class BooleanExam {
 public static void main(String[] args) {
  Boolean a = new Boolean(true);
  Boolean b = new Boolean(false);

  boolean aBool = a.booleanValue();
  boolean bBool = b.booleanValue();

  System.out.println(aBool);
  System.out.println(bBool);
 }
}


yengo หรือ buzzcity

วันพุธที่ 30 กรกฎาคม พ.ศ. 2557

Java java.lang Boolean compare(boolean x, boolean y)

Java java.lang Boolean compare(boolean x, boolean y)

Description Of Boolean: compare(boolean x, boolean y)


The java.lang.Boolean.compare(boolean x, boolean y) Compares two boolean values. The value returned is identical to what would be returned by: Boolean.valueOf(x).compareTo(Boolean.valueOf(y))

Boolean.compare(boolean x, boolean y) method returns the value 0 if x == y; a value less than 0 if !x && y; and a value greater than 0 if x && !y

Code Example Java Boolean

public class BooleanExam {
 public static void main(String[] args) {
  Boolean x = new Boolean(true);
  Boolean y = new Boolean(false);
  Boolean x2 = new Boolean(true);
  Boolean y2 = new Boolean(true);

  int aBool = Boolean.compare(x, y);
  int bBool = Boolean.compare(x2, y2);

  System.out.println(aBool);
  System.out.println(bBool);
 }
}


yengo หรือ buzzcity

วันอังคารที่ 29 กรกฎาคม พ.ศ. 2557

Java java.lang Boolean compareTo(Boolean b)

Java java.lang Boolean compareTo(Boolean b)

Description Of Boolean: compareTo(Boolean b)


The java.lang.Boolean.compareTo(Boolean b) compares this Boolean instance with another.

Boolean.compareTo(Boolean b) method returns, zero - if this object represents the same boolean value as the argument, a positive value - if this object represents true and the argument represents false, a negative value - if this object represents false and the argument represents true.

Code Example Java Boolean


public class BooleanExam {
 public static void main(String[] args) {
  Boolean x = new Boolean(true);
  Boolean y = new Boolean(false);

  int a = x.compareTo(y);
  String str1 = "Both values are equal ";
  String str2 = "Object value is true";
  String str3 = "Argument value is true";

  if (a == 0) {
   System.out.println(str1);
  } else if (a > 0) {
   System.out.println(str2);
  } else if (a < 0) {
   System.out.println(str3);
  }
 }
}

yengo หรือ buzzcity

วันจันทร์ที่ 28 กรกฎาคม พ.ศ. 2557

Java java.lang Boolean equals(Object obj)

Java java.lang Boolean equals(Object obj)

Description Of Boolean: equals(Object obj)


The java.lang.Boolean.equals(Object obj) returns true if and only if the argument is not null and is a Boolean object that represents the same boolean value as this object.

Boolean.equals(Object obj) method returns true if the Boolean objects represent the same value, false otherwise.

Code Example Java Boolean


public class BooleanExam {
 public static void main(String[] args) {
  Boolean x = new Boolean(true);
  Boolean y = new Boolean(false);

  boolean a = x.equals(y);
  System.out.println(a);
 }
}


yengo หรือ buzzcity

วันอาทิตย์ที่ 27 กรกฎาคม พ.ศ. 2557

Java java.lang Boolean getBoolean(String name)

Java java.lang Boolean getBoolean(String name)

Description Of Boolean: getBoolean(String name)


The java.lang.Boolean.getBoolean(String name) returns true if and only if the system property named by the argument exists and is equal to the string "true". A system property is accessible through getProperty, a method defined by the System class.

If there is no property with the specified name, or if the specified name is empty or null, then false is returned.

Boolean.getBoolean(String name) method returns the boolean value of the system property.

Code Example Java Boolean


public class BooleanExam {
 public static void main(String[] args) {
  boolean bool1, bool2;
  
  System.setProperty("demo1", "true");
  System.setProperty("demo2", "abcd");

  String s1 = System.getProperty("demo1");
  String s2 = System.getProperty("demo2");

  bool1 = Boolean.getBoolean("demo1");
  bool2 = Boolean.getBoolean("demo2");

  String str1 = "boolean value of system property demo1 is " + bool1;
  String str2 = "System property value of demo1 is " + s1;
  String str3 = "boolean value of system property demo2 is " + bool2;
  String str4 = "System property value of demo2 is " + s2;

  System.out.println(str1);
  System.out.println(str2);
  System.out.println(str3);
  System.out.println(str4);
 }
}


yengo หรือ buzzcity

Java java.lang Boolean hashCode()

Java java.lang Boolean hashCode()

Description Of Boolean: hashCode()


The java.lang.Boolean.hashCode() returns a hash code for this Boolean object.

Boolean.hashCode() method returns the integer 1231 if this object represents true and the integer 1237 if this object represents false.

Code Example Java Boolean


public class BooleanExam {
 public static void main(String[] args) {
  Boolean x = new Boolean(true);
  Boolean y = new Boolean(false);

  int i1, i2;

  i1 = x.hashCode();
  i2 = y.hashCode();

  String str1 = "Hash code of " + x + " is " + i1;
  String str2 = "Hash code of " + y + " is " + i2;

  // print i1, i2 values
  System.out.println(str1);
  System.out.println(str2);
 }
}


yengo หรือ buzzcity

วันเสาร์ที่ 26 กรกฎาคม พ.ศ. 2557

Java java.lang Boolean parseBoolean(String s)

Java java.lang Boolean parseBoolean(String s)

Description Of Boolean: parseBoolean(String s)


The java.lang.Boolean.parseBoolean(String s) parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".

Boolean.parseBoolean(String s) method returns the boolean represented by the string argument.

Code Example Java Boolean


public class BooleanExam {
 public static void main(String[] args) {
  // create and assign values to String's s1, s2
  String s1 = "TRue";
  String s2 = "yes";

  // create 2 boolean primitives bool1, bool2
  boolean bool1, bool2;
  
  bool1 = Boolean.parseBoolean(s1);
  bool2 = Boolean.parseBoolean(s2);

  String str1 = "Parse boolean on " + s1 + " gives " + bool1;
  String str2 = "Parse boolean on " + s2 + " gives " + bool2;

  // print b1, b2 values
  System.out.println(str1);
  System.out.println(str2);
 }
}


yengo หรือ buzzcity

Java java.lang Boolean toString(boolean b)

Java java.lang Boolean toString(boolean b)

Description Of Boolean: toString(boolean b)


The java.lang.Boolean.toString(boolean b) returns a String object representing this Boolean's value. If this object represents the value true, a string equal to "true" is returned. Otherwise, a string equal to "false" is returned.

Boolean.toString(boolean b) method returns a string representation of this object.

Code Example Java Boolean

public class BooleanExam {
 public static void main(String[] args) {
  Boolean b1 = new Boolean(true);
  Boolean b2 = new Boolean(null);

  String s1 = b1.toString();
  String s2 = b2.toString();

  String str1 = "String value of boolean object " + b1 + " is " + s1;
  String str2 = "String value of boolean object " + b2 + " is " + s2;

  // print s1, s2 values
  System.out.println(str1);
  System.out.println(str2);
 }
}


yengo หรือ buzzcity

วันศุกร์ที่ 25 กรกฎาคม พ.ศ. 2557

Java java.lang Boolean valueOf(boolean b)

Java java.lang Boolean valueOf(boolean b)

Description Of Boolean: valueOf(boolean b)

The java.lang.Boolean.valueOf(boolean b) returns a Boolean instance representing the specified boolean value. If the specified boolean value is true, this method returns Boolean.TRUE; if it is false, this method returns Boolean.FALSE.

If a new Boolean instance is not required, this method should generally be used in preference to the constructor Boolean(boolean), as this method is likely to yield significantly better space and time performance.

Boolean.valueOf(boolean b) method returns a Boolean instance representing b.

Code Example Java Boolean


public class BooleanExam {
 public static void main(String[] args) {
  boolean bool1 = true;
  boolean bool2 = false;

  Boolean b1 = Boolean.valueOf(bool1);
  Boolean b2 = Boolean.valueOf(bool2);

  // print b1, b2 values
  System.out.println(b1);
  System.out.println(b2);
 }
}


yengo หรือ buzzcity

Java java.lang Boolean valueOf(String s)

Java java.lang Boolean valueOf(String s)

Description Of Boolean: valueOf(String s)


The java.lang.Boolean.valueOf(String s) returns a Boolean with a value represented by the specified string. The Boolean returned represents a true value if the string argument is not null and is equal, ignoring case, to the string "true".

Boolean.valueOf(String s) method returns the Boolean value represented by the string.

Code Example Java Boolean


public class BooleanExam {
 public static void main(String[] args) {
  String s1 = null;
  String s2 = "false";

  Boolean b1 = Boolean.valueOf(s1);
  Boolean b2 = Boolean.valueOf(s2);

  // print b1, b2 values
  System.out.println(b1);
  System.out.println(b2);
 }
}


yengo หรือ buzzcity

วันพฤหัสบดีที่ 24 กรกฎาคม พ.ศ. 2557

POI org.apache.poi.hssf.usermodel HSSFWorkbook createSheet()

POI org.apache.poi.hssf.usermodel HSSFWorkbook createSheet()

Description Of HSSFWorkbook: createSheet()


The java.lang.HSSFWorkbook.createSheet() create Sheet of HSSFWorkbook

HSSFWorkbook.createSheet() method returns HSSFSheet

Code Example Java HSSFWorkbook


package exam.poi;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class PoiExam {
 public static void main(String[] args) {
  HSSFWorkbook workbook = new HSSFWorkbook();
  HSSFSheet sheet1 = workbook.createSheet();
  HSSFSheet sheet2 = workbook.createSheet();
  
  FileOutputStream fos = null;
  try {
   fos = new FileOutputStream(new File("PoiExam.xls"));
   workbook.write(fos);
   System.out.println("SUCCESS");
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   if (fos != null) {
    try {
     fos.flush();
     fos.close();
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  }
 }
}


yengo หรือ buzzcity

POI org.apache.poi.hssf.usermodel HSSFWorkbook createSheet(java.lang.String sheetname)

POI org.apache.poi.hssf.usermodel HSSFWorkbook createSheet(java.lang.String sheetname)

Description Of HSSFWorkbook: createSheet(java.lang.String sheetname)

The java.lang.HSSFWorkbook.createSheet(java.lang.String sheetname) create Sheet of HSSFWorkbook and contain sheet name

HSSFWorkbook.createSheet(java.lang.String sheetname) method returns HSSFSheet

Code Example Java HSSFWorkbook


package exam.poi;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class PoiExam {
 public static void main(String[] args) {
  HSSFWorkbook workbook = new HSSFWorkbook();
  HSSFSheet sheet1 = workbook.createSheet("sheetname 1");
  HSSFSheet sheet2 = workbook.createSheet("sheetname 2");
  
  FileOutputStream fos = null;
  try {
   fos = new FileOutputStream(new File("PoiExam.xls"));
   workbook.write(fos);
   System.out.println("SUCCESS");
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   if (fos != null) {
    try {
     fos.flush();
     fos.close();
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  }
 }
}


yengo หรือ buzzcity

วันพุธที่ 23 กรกฎาคม พ.ศ. 2557

POI org.apache.poi.hssf.usermodel HSSFWorkbook getNumberOfSheets()

POI org.apache.poi.hssf.usermodel HSSFWorkbook getNumberOfSheets()

Description Of HSSFWorkbook: getNumberOfSheets()

The java.lang.HSSFWorkbook.getNumberOfSheets() get the number of spreadsheets in the workbook (this will be three after serialization)

HSSFWorkbook.getNumberOfSheets() method returns number of sheet

Code Example Java HSSFWorkbook


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class PoiExam {
 public static void main(String[] args) {
  HSSFWorkbook workbook = new HSSFWorkbook();
  HSSFSheet sheet1 = workbook.createSheet("sheetname 1");
  HSSFSheet sheet2 = workbook.createSheet("sheetname 2");
  
  System.out.println("number of Sheet : " + workbook.getNumberOfSheets());
  
  FileOutputStream fos = null;
  try {
   fos = new FileOutputStream(new File("PoiExam.xls"));
   workbook.write(fos);
   System.out.println("SUCCESS" + workbook.getNumberOfSheets());
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   if (fos != null) {
    try {
     fos.flush();
     fos.close();
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  }
 }
}


yengo หรือ buzzcity

วันอังคารที่ 22 กรกฎาคม พ.ศ. 2557

POI org.apache.poi.hssf.usermodel HSSFWorkbook getSheetAt(int index)

POI org.apache.poi.hssf.usermodel HSSFWorkbook getSheetAt(int index)

Description Of HSSFWorkbook: getSheetAt(int index)


The java.lang.HSSFWorkbook.getSheetAt(int index) get the HSSFSheet object at the given index

HSSFWorkbook.getNumberOfSheets() method returns HSSFSheet

Code Example Java HSSFWorkbook


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class PoiExam {
 public static void main(String[] args) {
  HSSFWorkbook workbook = new HSSFWorkbook();
  HSSFSheet sheet1 = workbook.createSheet("sheetname 1");
  HSSFSheet sheet2 = workbook.createSheet("sheetname 2");
  
  HSSFSheet sheet = workbook.getSheetAt(0);
  System.out.println("sheet 0 name : " + sheet.getSheetName());
  
  FileOutputStream fos = null;
  try {
   fos = new FileOutputStream(new File("PoiExam.xls"));
   workbook.write(fos);
   System.out.println("SUCCESS");
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   if (fos != null) {
    try {
     fos.flush();
     fos.close();
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  }
 }
}


yengo หรือ buzzcity

POI org.apache.poi.hssf.usermodel HSSFWorkbook getSheetIndex(Sheet sheet)

POI org.apache.poi.hssf.usermodel HSSFWorkbook getSheetIndex(Sheet sheet)

Description Of HSSFWorkbook: getSheetIndex(Sheet sheet)


The java.lang.HSSFWorkbook.getSheetIndex(Sheet sheet) Returns the index of the given sheet

HSSFWorkbook.getSheetIndex(Sheet sheet) method returns int index of sheet

Code Example Java HSSFWorkbook


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class PoiExam {
 public static void main(String[] args) {
  HSSFWorkbook workbook = new HSSFWorkbook();
  HSSFSheet sheet1 = workbook.createSheet("sheetname 1");
  HSSFSheet sheet2 = workbook.createSheet("sheetname 2");
  
  int sheetindex1 = workbook.getSheetIndex(sheet1);
  int sheetindex2 = workbook.getSheetIndex(sheet2);
  System.out.println("sheet1 is index : " + sheetindex1);
  System.out.println("sheet1 is index : " + sheetindex2);
  
  FileOutputStream fos = null;
  try {
   fos = new FileOutputStream(new File("PoiExam.xls"));
   workbook.write(fos);
   System.out.println("SUCCESS");
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   if (fos != null) {
    try {
     fos.flush();
     fos.close();
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  }
 }
}

yengo หรือ buzzcity

วันจันทร์ที่ 21 กรกฎาคม พ.ศ. 2557

POI org.apache.poi.hssf.usermodel HSSFWorkbook getSheetIndex(java.lang.String name)

POI org.apache.poi.hssf.usermodel HSSFWorkbook getSheetIndex(java.lang.String name)

Description Of HSSFWorkbook: getSheetIndex(java.lang.String name)

The java.lang.HSSFWorkbook.getSheetIndex(java.lang.String name) Returns the index of the sheet by his name

HSSFWorkbook.getSheetIndex(java.lang.String name) method returns number of sheet by name, method return -1 is not found

Code Example Java HSSFWorkbook


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class PoiExam {
 public static void main(String[] args) {
  HSSFWorkbook workbook = new HSSFWorkbook();
  HSSFSheet sheet1 = workbook.createSheet("sheetname 1");
  HSSFSheet sheet2 = workbook.createSheet("sheetname 2");
  
  int sheetindex1 = workbook.getSheetIndex("sheetname 1");
  int sheetindex2 = workbook.getSheetIndex("sheetname 3");
  System.out.println("sheet1 is index : " + sheetindex1);
  System.out.println("sheet1 is index : " + sheetindex2);
  
  FileOutputStream fos = null;
  try {
   fos = new FileOutputStream(new File("PoiExam.xls"));
   workbook.write(fos);
   System.out.println("SUCCESS");
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   if (fos != null) {
    try {
     fos.flush();
     fos.close();
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  }
 }
}


yengo หรือ buzzcity

POI org.apache.poi.hssf.usermodel HSSFWorkbook getSheetName(int sheetIndex)

POI org.apache.poi.hssf.usermodel HSSFWorkbook getSheetName(int sheetIndex)


Description Of HSSFWorkbook: getSheetName(int sheetIndex)

The java.lang.HSSFWorkbook.getSheetName(int sheetIndex) Get the sheet name

HSSFWorkbook.getSheetName(int sheetIndex) method return string name of sheet

Code Example Java HSSFWorkbook


ตัวอย่างโค้ด
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class PoiExam {
 public static void main(String[] args) {
  HSSFWorkbook workbook = new HSSFWorkbook();
  HSSFSheet sheet1 = workbook.createSheet("sheetname 1");
  HSSFSheet sheet2 = workbook.createSheet("sheetname 2");
  
  System.out.println("sheet1 is name : " + workbook.getSheetName(0));
  System.out.println("sheet2 is name : " + workbook.getSheetName(1));
  
  FileOutputStream fos = null;
  try {
   fos = new FileOutputStream(new File("PoiExam.xls"));
   workbook.write(fos);
   System.out.println("SUCCESS");
  } catch (IOException e) {
   e.printStackTrace();
  } finally {
   if (fos != null) {
    try {
     fos.flush();
     fos.close();
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  }
 }
}

yengo หรือ buzzcity