javax.naming.CompoundName类的toString()方法用于使用通过属性传递的复合名称的语法来创建此复合名称对象的字符串表示形式。如果组件为空,则用空字符串表示。创建的非空化合物名称对象的字符串表示形式具有相同的语法属性,并且所有组件都由该语法在字符串表示形式中分开。
用法:
public String toString()
参数:此方法不接受任何内容。
返回值:此方法返回此复合名称的非空字符串表示形式。
以下示例程序旨在说明CompoundName.toString()方法:
程序1:
// Java program to demonstrate
// CompoundName.toString()
import java.util.Properties;
import javax.naming.CompoundName;
import javax.naming.InvalidNameException;
public class GFG {
public static void main(String[] args)
throws InvalidNameException
{
// need properties for CompoundName
Properties props = new Properties();
props.put("jndi.syntax.separator", "@");
props.put("jndi.syntax.direction",
"left_to_right");
// create compound name object
CompoundName CompoundName1
= new CompoundName(
"1@2@3@4@5@6@7",
props);
// apply toString()
String toString
= CompoundName1.toString();
// print value
System.out.println("toString:"
+ toString);
}
}
输出:
toString:1@2@3@4@5@6@7
程序2:
// Java program to demonstrate
// CompoundName.toString() method
import java.util.Properties;
import javax.naming.CompoundName;
import javax.naming.InvalidNameException;
public class GFG {
public static void main(String[] args)
throws InvalidNameException
{
// need properties for CompoundName
Properties props = new Properties();
props.put("jndi.syntax.separator", "/");
props.put("jndi.syntax.direction",
"left_to_right");
// create compound name object
CompoundName CompoundName1
= new CompoundName(
"c/e/d/v/a/b/z/y/x/f",
props);
// apply toString()
String toString
= CompoundName1.toString();
// print value
System.out.println("CompoundName:"
+ toString);
}
}
输出:
CompoundName:c/e/d/v/a/b/z/y/x/f
参考文献:https://docs.oracle.com/javase/10/docs/api/javax/naming/CompoundName.html#toString()
相关用法
- Java CompoundName get()用法及代码示例
- Java CompoundName add()用法及代码示例
- Java CompoundName startsWith()用法及代码示例
- Java CompoundName getPrefix()用法及代码示例
- Java CompoundName endsWith()用法及代码示例
- Java CompoundName equals()用法及代码示例
- Java CompoundName getSuffix()用法及代码示例
- Java CompoundName compareTo()用法及代码示例
- Java CompoundName clone()用法及代码示例
- Java CompoundName remove()用法及代码示例
- Java CompoundName size()用法及代码示例
- Java CompoundName hashCode()用法及代码示例
- Java CompoundName addAll()用法及代码示例
- Java CompoundName isEmpty()用法及代码示例
- Java CompoundName getAll()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 CompoundName toString() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。