Codota Logo
StringUtils
Code IndexAdd Codota to your IDE (free)

How to use
StringUtils
in
com.longlong.library.utils

Best Java code snippets using com.longlong.library.utils.StringUtils (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
BufferedReader b =
  • Codota IconInputStream in;new BufferedReader(new InputStreamReader(in))
  • Codota IconReader in;new BufferedReader(in)
  • Codota IconFile file;new BufferedReader(new FileReader(file))
  • Smart code suggestions by Codota
}
origin: w0080626/GankIO

/**
 * is null or its length is 0
 *
 * <pre>
 * isEmpty(null) = true;
 * isEmpty(&quot;&quot;) = true;
 * isEmpty(&quot;  &quot;) = false;
 * </pre>
 *
 * @param str
 * @return if string is null or its size is 0, return true, else return false.
 */
public static boolean isEmpty(String str) {
  return (str == null || str.length() == 0) && isBlank(str);
}
public static boolean notBlankAndNull(String str) {
origin: w0080626/GankIO

/**
 * encoded in utf-8, if exception, return defultReturn
 *
 * @param str
 * @param defultReturn
 * @return
 */
public static String utf8Encode(String str, String defultReturn) {
  if (!isEmpty(str) && str.getBytes().length != str.length()) {
    try {
      return URLEncoder.encode(str, "UTF-8");
    } catch (UnsupportedEncodingException e) {
      return defultReturn;
    }
  }
  return str;
}
origin: w0080626/GankIO

private void savePhoto() {
  String photoPath = BitmapUtils.saveImageToGallery(getView(), ((BitmapDrawable) getView().getImageView().getDrawable()).getBitmap(), FilenameUtils.getName(getData().getUrl()));
  if (StringUtils.notBlankAndNull(photoPath))
    SnackBarUtils.makeShort(getView().getToolbar(), "图片位置:" + photoPath).info();
  else
    SnackBarUtils.makeShort(getView().getToolbar(), "保存失败").danger();
}
origin: w0080626/GankIO

public int getInt(String key, int defValue) {
  String sValue = getString(key);
  if (!StringUtils.isEmpty(sValue)) {
    try {
      int iValue = Integer.parseInt(sValue);
      return iValue;
    } catch (Exception e) {
    }
  }
  return defValue;
}
origin: w0080626/GankIO

public float getFloat(String key, float defValue) {
  String sValue = getString(key);
  if (!StringUtils.isEmpty(sValue)) {
    try {
      float fValue = Float.parseFloat(sValue);
      return fValue;
    } catch (Exception e) {
    }
  }
  return defValue;
}
origin: w0080626/GankIO

public long getLong(String key, long defValue) {
  String sValue = getString(key);
  if (!StringUtils.isEmpty(sValue)) {
    try {
      long dValue = Long.parseLong(sValue);
      return dValue;
    } catch (Exception e) {
    }
  }
  return defValue;
}
origin: w0080626/GankIO

/**
 * 获取UDID
 * @param context
 * @return
 */
public static String getUDID(Context context) {
  String udid = Settings.Secure.getString(context.getContentResolver(),
      Settings.Secure.ANDROID_ID);
  if (StringUtils.isEmpty(udid) || udid.equals("9774d56d682e549c")
      || udid.length() < 15) {
    SecureRandom random = new SecureRandom();
    udid = new BigInteger(64, random).toString(16);
  }
  if ( StringUtils.isEmpty(udid) ) {
    udid = "";
  }
  return udid;
}
origin: w0080626/GankIO

/**
 * process special char in html
 *
 * <pre>
 * htmlEscapeCharsToString(null) = null;
 * htmlEscapeCharsToString("") = "";
 * htmlEscapeCharsToString("mp3") = "mp3";
 * htmlEscapeCharsToString("mp3&lt;") = "mp3<";
 * htmlEscapeCharsToString("mp3&gt;") = "mp3\>";
 * htmlEscapeCharsToString("mp3&amp;mp4") = "mp3&mp4";
 * htmlEscapeCharsToString("mp3&quot;mp4") = "mp3\"mp4";
 * htmlEscapeCharsToString("mp3&lt;&gt;&amp;&quot;mp4") = "mp3\<\>&\"mp4";
 * </pre>
 *
 * @param source
 * @return
 */
public static String htmlEscapeCharsToString(String source) {
  return StringUtils.isEmpty(source) ? source : source.replaceAll("&lt;", "<").replaceAll("&gt;", ">")
      .replaceAll("&amp;", "&").replaceAll("&quot;", "\"");
}
origin: w0080626/GankIO

if (isEmpty(s)) {
  return s;
origin: w0080626/GankIO

public boolean getBoolean(String key, boolean defValue) {
  String sValue = getString(key);
  if (!StringUtils.isEmpty(sValue)) {
    try {
      boolean bValue = Boolean.parseBoolean(sValue);
      return bValue;
    } catch (Exception e) {
    }
  }
  return defValue;
}
origin: w0080626/GankIO

public Double getDouble(String key, double defValue) {
  String sValue = getString(key);
  if (!StringUtils.isEmpty(sValue)) {
    try {
      double dValue = Double.parseDouble(sValue);
      return dValue;
    } catch (Exception e) {
    }
  }
  return defValue;
}
origin: w0080626/GankIO

/**
 * encoded in utf-8
 *
 * <pre>
 * utf8Encode(null)        =   null
 * utf8Encode("")          =   "";
 * utf8Encode("aa")        =   "aa";
 * utf8Encode("啊啊啊啊")   = "%E5%95%8A%E5%95%8A%E5%95%8A%E5%95%8A";
 * </pre>
 *
 * @param str
 * @return
 * @throws UnsupportedEncodingException if an error occurs
 */
public static String utf8Encode(String str) {
  if (!isEmpty(str) && str.getBytes().length != str.length()) {
    try {
      return URLEncoder.encode(str, "UTF-8");
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException("UnsupportedEncodingException occurred. ", e);
    }
  }
  return str;
}
origin: w0080626/GankIO

if (isEmpty(s)) {
  return s;
origin: w0080626/GankIO

/**
 * 获取IMEI
 * @param context
 * @return
 */
public static String getIMEI(Context context) {
  TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  String imei = tm.getDeviceId();
  if ( StringUtils.isEmpty(imei) ) {
    imei = "";
  }
  return imei;
}
origin: w0080626/GankIO

/**
 * 获取Manifest Meta Data
 * @param context
 * @param metaKey
 * @return
 */
public static String getMetaData(Context context, String metaKey) {
  String name = context.getPackageName();
  ApplicationInfo appInfo;
  String msg = "";
  try {
    appInfo = context.getPackageManager().getApplicationInfo(name,
        PackageManager.GET_META_DATA);
    msg = appInfo.metaData.getString(metaKey);
  } catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
  }
  if (StringUtils.isEmpty(msg)) {
    return "";
  }
  return msg;
}
origin: w0080626/GankIO

/**
 * 获得apk版本号
 * @param context
 * @return
 */
public static String getVersionName(Context context) {
  String version = "";
  // 获取packagemanager的实例
  PackageManager packageManager = context.getPackageManager();
  // getPackageName()是你当前类的包名,0代表是获取版本信息
  PackageInfo packInfo;
  try {
    packInfo = packageManager.getPackageInfo(context.getPackageName(),
        0);
    version = packInfo.versionName;
  } catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
  }
  if (StringUtils.isEmpty(version)) {
    version = "";
  }
  return version;
}
origin: w0080626/GankIO

/**
 * capitalize first letter
 *
 * <pre>
 * capitalizeFirstLetter(null)     =   null;
 * capitalizeFirstLetter("")       =   "";
 * capitalizeFirstLetter("2ab")    =   "2ab"
 * capitalizeFirstLetter("a")      =   "A"
 * capitalizeFirstLetter("ab")     =   "Ab"
 * capitalizeFirstLetter("Abc")    =   "Abc"
 * </pre>
 *
 * @param str
 * @return
 */
public static String capitalizeFirstLetter(String str) {
  if (isEmpty(str)) {
    return str;
  }
  char c = str.charAt(0);
  return (!Character.isLetter(c) || Character.isUpperCase(c)) ? str : new StringBuilder(str.length())
      .append(Character.toUpperCase(c)).append(str.substring(1)).toString();
}
origin: w0080626/GankIO

if (StringUtils.isEmpty(key)) {
  return;
if ( StringUtils.isEmpty(value) ) {
  value = "";
origin: w0080626/GankIO

if (isEmpty(href)) {
  return "";
origin: w0080626/GankIO

if ( StringUtils.isEmpty(key) ) {
  return null;
com.longlong.library.utilsStringUtils

Javadoc

Desction:String工具类 Author:pengjianbo Date:15/9/17 下午4:22

Most used methods

  • isBlank
    is null or its length is 0 or it is made by space isBlank(null) = true; isBlank("") = true; isBla
  • isEmpty
    is null or its length is 0 isEmpty(null) = true; isEmpty("") = true; isEmpty(" ") = false;
  • notBlankAndNull

Popular in Java

  • Start an intent from android
  • getResourceAsStream (ClassLoader)
  • getContentResolver (Context)
  • startActivity (Activity)
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • ConcurrentHashMap (java.util.concurrent)
    A hash table supporting full concurrency of retrievals and adjustable expected concurrency for updat
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • Reference (javax.naming)
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now