Blog Archive

Wednesday, March 28, 2018

Sample java code for arraylist and string functionalities for your UDF to solve mapping issues

Om



import java.util.ArrayList;
public class ContainsExample {
   public static void main(String[] args) {

      ArrayList al = new ArrayList();
      al.add("pen asdfasdfafds");
      al.add("pencil");
      al.add("ink asdfasdfafds");
      al.add("notebpen asdfafds");
      int i=0;
    /*  for (String type : al) {
            if (type.contains("pen")) {
                System.out.println("contains test:original Value: "+type+"-->list value:"+i+" "+al.get(i));
            }i++;
        }*/     
      for (String type : al) {
          if (type.substring(1,3).equals("en")) {
              System.out.println("en found: "+type+"-->list value:"+i+" "+al.get(i));
          }i++;
      }
   }
}
output
---------------
en found: pen asdfasdfafds-->list value:0 pen asdfasdfafds
en found: pencil-->list value:1 pencil

No comments:

Post a Comment