|
以下实例演示了使用LinkedList.add() 和 LinkedSet.set() 方法来修改链接中的元素: Main.java 文件import java . util . LinkedList ;
public class Main {
public static void main ( String [ ] a ) {
LinkedList<String> officers = new LinkedList<String> ( ) ;
officers . add ( " B " ) ;
officers . add ( " B " ) ;
officers . add ( " T " ) ;
officers . add ( " H " ) ;
officers . add ( " P " ) ;
System . out . println ( officers ) ;
officers . set ( 2 , " M " ) ;
System . out . println ( officers ) ;
}
} |
以上代码运行输出结果为:
[B, B, T, H, P]
[B, B, M, H, P]
程序猿的技术大观园:www.javathinker.net
[这个贴子最后由 flybird 在 2020-01-23 21:05:56 重新编辑]
|
|