Wednesday 12 August 2015

Built-in functions used frequently

CONTAINS & EQUALS :

row1.contains("ram")
row2.equals("Name")

LASTINDEXOF :
("tFileList_1_CURRENT_FILE")).lastIndexOf("."))

SUBSTRING:
m-- starts from 0 .. refers to the position.
n -- starts from 1 -- refers to the position itself (not the no: of the characters)

Input  :  "ABCD".substring(0,2)
Result :   ABC
substring(m,n)


GETTING CURRENT FILEPATH  IN tFILELIST :
((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"))

GETTING CURRENT FILENAME FROM  tFILELIST :
((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(0,((String)globalMap.get
("tFileList_1_CURRENT_FILE")).lastIndexOf("."))

replace() Example :
-------------------------
we can use this for replacing special characters in a string
String input_row="abcd:[],kdkkxyzkll:[],";

String abc="{\"NOTIFICATION_RESPONSE\":{"+input_row.replace(":[],",":\"\"")+"}}";
System.out.println(abc);
Output :
-----------
{"NOTIFICATION_RESPONSE":{abcd:""kdkkxyzkll:""}}

Note :  Go for replace() if  replaceAll() is not working.
replaceAll() will not work for dollar ($),doublequotes("),comma(,) etc special characters, in such cases you can go for replace().


split() Example :
-----------------------
package com.myjava.string;
public class MyStrSplit {
    public static void main(String a[]){
     
        String str = "This program splits a string based on space";
        String[] tokens = str.split(" ");
        for(String s:tokens){
            System.out.println(s);
        }
        str = "This     program  splits a string based on space";
        tokens = str.split("\\s+");
    }
}

COURTS : CASES : LAWYERS : JUDGES : ::::::::: VICTIMS : ACCUSED

  *We have got so many SMART people in our COUNTRY. *we have got so many IIT completed SMART students in our COUNTRY. * we have got so many ...