tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Commons Lang3 > Strings > Overlay

Overlay 

Apache Commons Lang 3.0 is a java library with lot of utilities and reusable components. This requires the library commons-lang3-3.0.1.jar to be in classpath. The following example shows using StringUtils.overlay() API. It overlays part of the given string with another string.

File Name  :  
com/bethecoder/tutorials/commons_lang/tests/strings/OverlayTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.commons_lang.tests.strings;

import org.apache.commons.lang3.StringUtils;

public class OverlayTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    String credit_card = "4840282024288624";
    System.out.println(StringUtils.overlay(credit_card, "****"04));
    System.out.println(StringUtils.overlay(credit_card, "****"24));
    System.out.println(StringUtils.overlay(credit_card, "****"48));
    System.out.println(StringUtils.overlay(credit_card, "****"812));
  }

}
   

It gives the following output,
****282024288624
48****282024288624
4840****24288624
48402820****8624



 
  


  
bl  br