Convert Figma logo to code with AI

dromara logohutool

🍬A set of tools that keep Java sweet.

28,911
7,475
28,911
3

Top Related Projects

25,732

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.

50,119

Google core libraries for Java

Apache Commons Lang

Spring Framework

9,077

Main Portal page for the Jackson project

Apache Commons IO

Quick Overview

Hutool is a comprehensive Java utility library that aims to simplify development by providing a wide range of tools and helper methods. It covers various aspects of Java programming, including string manipulation, date handling, file operations, network utilities, and more, all designed to improve code readability and reduce boilerplate.

Pros

  • Extensive collection of utility methods covering many common programming tasks
  • Well-documented with clear examples and explanations
  • Actively maintained with regular updates and improvements
  • Lightweight and easy to integrate into existing projects

Cons

  • Some developers may prefer using separate, specialized libraries for specific tasks
  • Learning curve for developers unfamiliar with the library's structure and naming conventions
  • Potential for dependency conflicts with other libraries that provide similar functionality
  • May introduce unnecessary dependencies for projects that only need a small subset of features

Code Examples

  1. String manipulation:
String result = StrUtil.format("Hello, {}! Today is {}", "World", DateUtil.today());
System.out.println(result);

This example demonstrates string formatting and date handling using Hutool's StrUtil and DateUtil classes.

  1. File operations:
File file = FileUtil.file("example.txt");
FileUtil.writeUtf8String("Hello, Hutool!", file);
String content = FileUtil.readUtf8String(file);
System.out.println(content);

This code snippet shows how to create a file, write content to it, and read from it using Hutool's FileUtil class.

  1. HTTP requests:
String result = HttpUtil.get("https://api.example.com/data");
JSONObject json = JSONUtil.parseObj(result);
System.out.println(json.getStr("key"));

This example demonstrates making an HTTP GET request and parsing the JSON response using Hutool's HttpUtil and JSONUtil classes.

Getting Started

To use Hutool in your project, add the following dependency to your Maven pom.xml file:

<dependency>
    <groupId>cn.hutool</groupId>
    <artifactId>hutool-all</artifactId>
    <version>5.8.18</version>
</dependency>

For Gradle, add this to your build.gradle file:

implementation 'cn.hutool:hutool-all:5.8.18'

After adding the dependency, you can start using Hutool's utility classes in your Java code by importing the required classes:

import cn.hutool.core.util.StrUtil;
import cn.hutool.core.date.DateUtil;
// Import other Hutool classes as needed

Competitor Comparisons

25,732

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.

Pros of Fastjson

  • Faster JSON parsing and serialization performance
  • More extensive JSON-specific features and customization options
  • Better support for complex JSON structures and data types

Cons of Fastjson

  • Narrower focus on JSON processing compared to Hutool's broader utility offerings
  • Less frequent updates and maintenance in recent years
  • Some security vulnerabilities have been reported in the past

Code Comparison

Fastjson:

String jsonString = JSON.toJSONString(object);
MyObject myObject = JSON.parseObject(jsonString, MyObject.class);

Hutool:

String jsonString = JSONUtil.toJsonStr(object);
MyObject myObject = JSONUtil.toBean(jsonString, MyObject.class);

Summary

Fastjson excels in JSON processing with superior performance and features, while Hutool offers a broader range of utility functions beyond JSON handling. Fastjson is ideal for projects with heavy JSON requirements, whereas Hutool provides a more comprehensive toolkit for various Java development needs. The choice between the two depends on the specific requirements of your project and the balance between specialized JSON capabilities and general-purpose utilities.

50,119

Google core libraries for Java

Pros of Guava

  • More comprehensive and mature library with a wider range of utilities
  • Better documentation and extensive JavaDoc
  • Strong support from Google and a large community

Cons of Guava

  • Larger library size, which may increase application footprint
  • Steeper learning curve due to its extensive API
  • Less frequent updates compared to Hutool

Code Comparison

Guava:

List<String> list = Lists.newArrayList("a", "b", "c");
Multimap<String, Integer> multimap = ArrayListMultimap.create();
Optional<String> optional = Optional.of("value");

Hutool:

List<String> list = CollUtil.newArrayList("a", "b", "c");
Dict dict = Dict.create().set("key", "value");
Optional<String> optional = Optional.ofNullable("value");

Summary

Guava is a more established and feature-rich library, offering a wide range of utilities backed by Google. It provides excellent documentation but comes with a larger footprint and steeper learning curve. Hutool, on the other hand, is a lighter alternative with more frequent updates and a focus on simplicity. The choice between the two depends on project requirements, team familiarity, and performance considerations.

Apache Commons Lang

Pros of Commons Lang

  • Mature and well-established project with a long history of development and community support
  • Extensive documentation and widespread adoption in the Java ecosystem
  • Rigorous testing and quality assurance processes as part of the Apache Software Foundation

Cons of Commons Lang

  • More focused on core Java language utilities, lacking some of the broader functionality found in Hutool
  • Less frequent updates and slower adoption of new Java features compared to Hutool
  • Larger dependency size due to its comprehensive nature

Code Comparison

Commons Lang:

String result = StringUtils.capitalize("hello");
boolean isEmpty = StringUtils.isEmpty(myString);
String[] parts = StringUtils.split("a,b,c", ",");

Hutool:

String result = StrUtil.upperFirst("hello");
boolean isEmpty = StrUtil.isEmpty(myString);
String[] parts = StrUtil.split("a,b,c", ",");

Both libraries offer similar functionality for common string operations, but Hutool tends to have more concise method names. Commons Lang provides a wider range of utilities specifically for Java language features, while Hutool covers a broader spectrum of utility functions beyond just language-specific operations.

Spring Framework

Pros of Spring Framework

  • Comprehensive ecosystem with extensive documentation and community support
  • Robust dependency injection and aspect-oriented programming features
  • Seamless integration with various Java EE technologies and third-party libraries

Cons of Spring Framework

  • Steeper learning curve due to its complexity and vast feature set
  • Heavier footprint and potential performance overhead for smaller applications
  • More verbose configuration and setup compared to lightweight alternatives

Code Comparison

Spring Framework:

@RestController
public class HelloController {
    @GetMapping("/hello")
    public String hello() {
        return "Hello, World!";
    }
}

Hutool:

public class HelloServer {
    public static void main(String[] args) {
        HttpUtil.createServer(8080)
            .addAction("/hello", (req, res) -> res.write("Hello, World!"))
            .start();
    }
}

Spring Framework offers a more structured and annotation-based approach, while Hutool provides a simpler and more concise method for creating a basic HTTP server. Spring's approach is better suited for larger, enterprise-level applications, whereas Hutool's simplicity makes it ideal for smaller projects or quick prototyping.

9,077

Main Portal page for the Jackson project

Pros of Jackson

  • Widely adopted industry standard for JSON processing in Java
  • Extensive ecosystem with numerous modules for various data formats
  • High performance and flexibility for complex data structures

Cons of Jackson

  • Steeper learning curve for advanced features
  • Can be overkill for simple JSON operations
  • Requires more configuration for custom serialization/deserialization

Code Comparison

Jackson:

ObjectMapper mapper = new ObjectMapper();
MyObject obj = mapper.readValue(jsonString, MyObject.class);
String json = mapper.writeValueAsString(obj);

Hutool:

JSONObject jsonObject = JSONUtil.parseObj(jsonString);
MyObject obj = JSONUtil.toBean(jsonObject, MyObject.class);
String json = JSONUtil.toJsonStr(obj);

Summary

Jackson is a powerful and versatile JSON processing library, while Hutool is a comprehensive utility library that includes JSON handling among many other features. Jackson excels in complex JSON operations and offers more customization options, but Hutool provides a simpler API for basic JSON tasks and includes a wide range of other utility functions. The choice between them depends on the specific project requirements and the need for additional utility functions beyond JSON processing.

Apache Commons IO

Pros of Commons IO

  • More mature and widely adopted in the Java ecosystem
  • Focused specifically on I/O operations, providing deep functionality
  • Backed by the Apache Software Foundation, ensuring long-term support

Cons of Commons IO

  • Limited scope compared to Hutool's broader utility offerings
  • Less frequent updates and releases
  • Larger dependency size for projects only needing basic I/O operations

Code Comparison

Commons IO:

FileUtils.copyFile(srcFile, destFile);
String content = FileUtils.readFileToString(file, "UTF-8");
IOUtils.closeQuietly(inputStream);

Hutool:

FileUtil.copy(srcFile, destFile, true);
String content = FileUtil.readString(file, CharsetUtil.CHARSET_UTF_8);
IoUtil.close(inputStream);

Summary

Commons IO is a specialized library for I/O operations, offering deep functionality and widespread adoption. Hutool, on the other hand, is a more comprehensive utility library that includes I/O operations among many other features. While Commons IO benefits from Apache's backing and maturity, Hutool provides a broader range of utilities in a single package. The choice between them depends on project requirements and whether a focused I/O library or a more general-purpose utility suite is needed.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

🍬A set of tools that keep Java sweet.

👉 https://hutool.cn/ 👈

star github star




🌎English Documentation


📚简介

Hutool是一个功能丰富且易用的Java工具库,通过诸多实用工具类的使用,旨在帮助开发者快速、便捷地完成各类开发任务。 这些封装的工具涵盖了字符串、数字、集合、编码、日期、文件、IO、加密、数据库JDBC、JSON、HTTP客户端等一系列操作, 可以满足各种不同的开发需求。

🎁Hutool名称的由来

Hutool = Hu + tool,是原公司项目底层代码剥离后的开源库,“Hu”是公司名称的表示,tool表示工具。Hutool谐音“糊涂”,一方面简洁易懂,一方面寓意“难得糊涂”。

🍺Hutool理念

Hutool既是一个工具集,也是一个知识库,我们从不自诩代码原创,大多数工具类都是搬运而来,因此:

  • 你可以引入使用,也可以拷贝和修改使用,而**不必标注任何信息**,只是希望能把bug及时反馈回来。
  • 我们努力健全中文注释,为源码学习者提供良好地学习环境,争取做到人人都能看得懂。

🛠️包含组件

一个Java基础工具类,对文件、流、加密解密、转码、正则、线程、XML等JDK方法进行封装,组成各种Util工具类,同时提供以下组件:

模块介绍
hutool-aopJDK动态代理封装,提供非IOC下的切面支持
hutool-bloomFilter布隆过滤,提供一些Hash算法的布隆过滤
hutool-cache简单缓存实现
hutool-core核心,包括Bean操作、日期、各种Util等
hutool-cron定时任务模块,提供类Crontab表达式的定时任务
hutool-crypto加密解密模块,提供对称、非对称和摘要算法封装
hutool-dbJDBC封装后的数据操作,基于ActiveRecord思想
hutool-dfa基于DFA模型的多关键字查找
hutool-extra扩展模块,对第三方封装(模板引擎、邮件、Servlet、二维码、Emoji、FTP、分词等)
hutool-http基于HttpUrlConnection的Http客户端封装
hutool-log自动识别日志实现的日志门面
hutool-script脚本执行封装,例如Javascript
hutool-setting功能更强大的Setting配置文件和Properties封装
hutool-system系统参数调用封装(JVM信息等)
hutool-jsonJSON实现
hutool-captcha图片验证码实现
hutool-poi针对POI中Excel和Word的封装
hutool-socket基于Java的NIO和AIO的Socket封装
hutool-jwtJSON Web Token (JWT)封装实现

可以根据需求对每个模块单独引入,也可以通过引入hutool-all方式引入所有模块。


📝文档

📘中文文档

📘中文备用文档

📙参考API

🎬视频介绍


🪙支持Hutool

💳捐赠

如果你觉得Hutool不错,可以捐赠请维护者吃包辣条~,在此表示感谢^_^。

Gitee上捐赠

👕周边商店

你也可以通过购买Hutool的周边商品来支持Hutool维护哦!

我们提供了印有Hutool Logo的周边商品,欢迎点击购买支持:

👉 Hutool 周边商店 👈


📦安装

🍊Maven

在项目的pom.xml的dependencies中加入以下内容:

<dependency>
    <groupId>cn.hutool</groupId>
    <artifactId>hutool-all</artifactId>
    <version>5.8.32</version>
</dependency>

🍐Gradle

implementation 'cn.hutool:hutool-all:5.8.32'

📥下载jar

点击以下链接,下载hutool-all-X.X.X.jar即可:

🔔️注意 Hutool 5.x支持JDK8+,对Android平台没有测试,不能保证所有工具类或工具方法可用。 如果你的项目使用JDK7,请使用Hutool 4.x版本(不再更新)

🚽编译安装

访问Hutool的Gitee主页:https://gitee.com/dromara/hutool 下载整个项目源码(v5-master或v5-dev分支都可)然后进入Hutool项目目录执行:

./hutool.sh install

然后就可以使用Maven引入了。


🏗️添砖加瓦

🎋分支说明

Hutool的源码分为两个分支,功能如下:

分支作用
v5-master主分支,release版本使用的分支,与中央库提交的jar一致,不接收任何pr或修改
v5-dev开发分支,默认为下个版本的SNAPSHOT版本,接受修改或pr

🐞提供bug反馈或建议

提交问题反馈请说明正在使用的JDK版本呢、Hutool版本和相关依赖库版本。

🧬贡献代码的步骤

  1. 在Gitee或者Github上fork项目到自己的repo
  2. 把fork过去的项目也就是你的项目clone到你的本地
  3. 修改代码(记得一定要修改v5-dev分支)
  4. commit后push到自己的库(v5-dev分支)
  5. 登录Gitee或Github在你首页可以看到一个 pull request 按钮,点击它,填写一些说明信息,然后提交即可。
  6. 等待维护者合并

📐PR遵照的原则

Hutool欢迎任何人为Hutool添砖加瓦,贡献代码,不过维护者是一个强迫症患者,为了照顾病人,需要提交的pr(pull request)符合一些规范,规范如下:

  1. 注释完备,尤其每个新增的方法应按照Java文档规范标明方法说明、参数说明、返回值说明等信息,必要时请添加单元测试,如果愿意,也可以加上你的大名。
  2. Hutool的缩进按照Eclipse(不要跟我说IDEA多好用,维护者非常懒,学不会,IDEA真香,改了Eclipse快捷键后舒服多了)默认(tab)缩进,所以请遵守(不要和我争执空格与tab的问题,这是一个病人的习惯)。
  3. 新加的方法不要使用第三方库的方法,Hutool遵循无依赖原则(除非在extra模块中加方法工具)。
  4. 请pull request到v5-dev分支。Hutool在5.x版本后使用了新的分支:v5-master是主分支,表示已经发布中央库的版本,这个分支不允许pr,也不允许修改。
  5. 我们如果关闭了你的issue或pr,请不要诧异,这是我们保持问题处理整洁的一种方式,你依旧可以继续讨论,当有讨论结果时我们会重新打开。

📖文档源码地址

文档源码地址 点击前往添砖加瓦


⭐Star Hutool

Stargazers over time