java的decimalFormat_Java DecimalFormat equals()用法及代码示例

equals()方法是java.text.DecimalFormat类的内置方法,它接受一个作为对象的参数,如果该参数对象与该对象相同,则返回true,否则返回false。

用法:

public boolean equals(Object arg)

参数:该函数接受单个强制参数arg,该参数指定要与之进行比较的对象。

返回值:该函数返回一个布尔值。如果两个对象相同,则返回true,否则返回false。

下面是上述功能的实现:

程序1:

// Java program to illustrate the

// equals() method

import java.text.DecimalFormat;

import java.util.Currency;

import java.util.Locale;

public class Main {

public static void main(String[] args)

{

// Get the Currency Instance

DecimalFormat dF1 = new DecimalFormat();

dF1.getCurrencyInstance();

// Get the Currency Instance

DecimalFormat dF2 = new DecimalFormat();

dF2.getCurrencyInstance();

// Check if equal or not

if (dF1.equals(dF2))

System.out.println("Yes both are equal");

else

System.out.println("Yes both are not equal");

}

}

输出:

Yes both are equal

程序2:

// Java program to illustrate the

// equals() method

import java.text.DecimalFormat;

import java.util.Currency;

import java.util.Locale;

public class Main {

public static void main(String[] args)

{

// Get the Currency Instance

DecimalFormat dF1 = new DecimalFormat();

dF1.getCurrencyInstance();

// Get Instance

DecimalFormat dF2 = new DecimalFormat();

dF2.setCurrency(Currency.getInstance(Locale.GERMANY));

// Check if equal or not

if (dF1.equals(dF2))

System.out.println("Yes both are equal");

else

System.out.println("Yes both are not equal");

}

}

输出:

Yes both are not equal

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值