In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
JAVA in how to remove the space in the object, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
Use the JAVA reflection mechanism to remove spaces from string attributes in an object.
Note: if the attribute itself is a "", it will also be replaced. If you need to filter, just append the judgment after objectfiltering null.
Public static void objectToTrim (Object obj) throws IllegalAccessException {Map map = new HashMap (); Field [] declaredFields = obj.getClass (). GetDeclaredFields (); for (Field field:declaredFields) {String type = field.getType (). GetCanonicalName (); if (StringUtils.equals (java.lang.String), type) {field.setAccessible (true); Object object = field.get (obj) If (object! = null) {String trim = object.toString () .replace ("", "); map.put (field.getName (), trim) } for (Field field:declaredFields) {if (map.get (field.getName ())! = null) {String s = map.get (field.getName ()); field.setAccessible (true); field.set (obj,s) }} public static void main (String [] args) throws IllegalAccessException {IdCode idCode = new IdCode (); idCode.setDeleteFlag (1); idCode.setCreateDate (LocalDateTime.now ()); idCode.setDeptId (""); idCode.setEducationUrl ("abvc"); idCode.setIdCode ("b c ddd"); System.out.println (idCode.toString ()) System.out.println ("= removed spaces ="); objectToTrim (idCode); System.out.println (idCode.toString ());}
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.