Java Java String Format toJava(String text)

Here you can find the source of toJava(String text)

Description

Transforms special characters in characters understandable for java

The following characters are replaced with corresponding character entities :

Character Encoding
< <
> >
& &
" "
' '

License

Open Source License

Declaration

public static String toJava(String text) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from   ww  w .  j  ava  2 s .  c o m
       Transforms special characters in characters understandable for java
           
       <P>The following characters are replaced with corresponding character entities :
       <table border='1' cellpadding='3' cellspacing='0'>
       <tr><th> Character </th><th> Encoding </th></tr>
       <tr><td> < </td><td> &lt; </td></tr>
       <tr><td> > </td><td> &gt; </td></tr>
       <tr><td> & </td><td> &amp; </td></tr>
       <tr><td> " </td><td> &quot;</td></tr>
       <tr><td> ' </td><td> &apos;</td></tr>
       </table>
      */
    public static String toJava(String text) {
        return text.replace("&lt;", "<").replace("&gt;", ">").replace("&quot;", "\"").replace("&apos;", "\'")
                .replace("&amp;", "&");
    }
}

Related

  1. convertToJavaIdentity(String original, boolean firstCharacterUpperCase, boolean normalize)
  2. convertToJavaUnicode(String input, Character start1, Character end1, Character start2, Character end2)
  3. toJava(CharSequence str)
  4. toJava(final double[] doubles)
  5. toJava(String name)
  6. toJAVA(String unicode)
  7. toJavaBeanPropertyName(String prop)
  8. toJavaBool(byte goBool)
  9. toJavaCasing(final String pName)