Skip to main content

Posts

Showing posts from October, 2015

string Buffer

                            String    Buffer StringBuffer class: StringBuffer class lets the user to modify the characters present within the string while String class always returns the new String object containing the modified string and the original string remains unchanged . The StringBuffer class reverses the 16 additional character spaces for further advancement in the string. Constructors of the StringBuffer class: a) StringBuffer(): It will create the blank string buffer class object. b) StringBuffer(int length): This argument will set the length of the String . E.g. StringBuffer sb=new StringBuffer(5); sb="computer"; System.out.println(sb); Output: compu  StringBuffer(String s ): where: s is the string with which we want to initialize the StringBuffer class object. E.g. StringBuffer sb=new StringBuffer("hello"); System.out.println(sb); Output: ...

concat & trim

                                                          Concat & Trim  1.         concat(): This method is used for conceiting two strings String concat(String ob) E.g.                                     String s1="hello";                                     String s2="world";                                ...

getchars & valueof

                                                         getchars & valueof 1.         valueOf(): This method is used to convert the string into any other data type The general form is. String valueOf(double) String  valueOf(int ) String valueOf(char [ ]) 2.         getChars(): This method is used to extract the specific group of characters from the string and assign it into the character array. The general form is: getChars(int sindex,int eindex,char t[],int position) Where:                                     sindex is the starting index position . eindex is the ending...

return

                                                              use of return Prograam class Sample {             int i,j;             Sample()             {                         i=0;                         j=0;             }             Sample(int a,int b)    ...

Use of Replace

                                                                                  Replace                                                                        1.      replace():  This method is used to replace all the occurrences of a single character with some another character, within the string. The general form is. String replace(char ch1,char ch2) Where:                                     ch1 is ...

substring method

     substring():  This method is used to extract the substring from a string The general form is. String substring(int sindex) String substring(int sindex,int eindex) Where:                                     sindex is the starting index position                                     eindex is the ending index position.                                     but the actuall string is extracted upto the position eindex-1 Eg...

To remove multiple row

                                                              To remove multiple row     DefaultTableModel model=(DefaultTableModel)jTable1.getModel();             if (model.getRowCount() > 0) {                 for (int i = model.getRowCount() - 1; i > -1; i--) {                     model.removeRow(i);                 }

lower & upper case

                                                      lower & upper case      toUpperCase() : This method is used to convert the string into upper case The general form is. String toUpperCase() E.g. String s="This Fine"; System.out.println(s.toUpperCase()); Output: THIS FINE toLowerCase(): This method is used to convert the string into lower case The general form is. String toLowerCase() E.g. String s="This Fine"; System.out.println(s.toLowerCase()); Output: this fine

use lastIndexOf

     lastIndexOf(): This method is used to search for the character or a string within the another string from the last character position. The general form is. lastIndexOf(int ch) lastIndexOf(String s) E.g. String s="this is a very fine day"; System.out.println(s.lastIndexOf('i')); System.out.println(s.lastIndexOf("is")); Output: 17 5

check no of occurence

                       check no of occurence Program- Write a java program to find out the number of times a substring occurs within the string class Search {             public static void main(String args[ ])             {             String s=new String("this is a this is a this is a that");             String p=new String(args[0]);             int count=0;             int position=0;             while(position=s.indexOf(p,position)!=-1)             {  ...

add and sub datefrom current date

         add and sub date from current date                                                                 int monthsToAdd = 4; int monthsToSubtract = 10; Calendar c = Calendar.getInstance(); System.out.println("Current date : " + (c.get(Calendar.MONTH) + 1) + "-" + c.get(Calendar.DATE) + "-" + c.get(Calendar.YEAR)); // add months to current date c.add(Calendar.MONTH, monthsToAdd); System.out.println("Date (after): " + (c.get(Calendar.MONTH) + 1) + "-" + c.get(Calendar.DATE) + "-" + c.get(Calendar.YEAR)); c = Calendar.getInstance();      // sub  months to current date c.add(Calendar.MONTH, -monthsToSubtract); System.out.println("Date (before): " + (c.get(Calendar.MONTH) + 1) + "-" + c.get(Calendar.DATE) + "-" + c.get(Calendar.YEAR))...

1. indexOf():

                                                                     indexOf() : This method is used to search a character or a string within the string. There are two forms of this function:                         indexOf(int ch)                         indexOf(String s) Where:             ch specify the ASCII  value of the character which we want to search             s will be the substring which you want to search The function returns the index number of the first...