码迷,mamicode.com
首页 > 编程语言 > 详细

Java-Arrays类-fill()方法详解

时间:2017-11-04 19:26:52      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:false   bool   str   包括   hello   ati   static   var   class   

fill()方法使用参考

声明举例:

public static void fill(int[] a, form, to, int var) 

参数:

a--数组

form--替换开始位置(包括)

to--替换结束位置(不包括)

var--要替换的值

使用参考实例:

public class Test {
    
    public static void main(String[] args) {
        
        int[] a = new int[]{1,2,3,4,5,6};
        System.out.println(Arrays.toString(a));  //{1,2,3,4,5,6}
    
        Arrays.fill(a, 0);
        System.out.println(Arrays.toString(a));  //{0,0,0,0,0,0}    
        
        int[] b = new int[]{1,2,3,4,5,6};
        Arrays.fill(b, 2, 4, 0);
        System.out.println(Arrays.toString(b));  //{1,2,0,0,5,6}
        
        Boolean[] c = {true,false};
        System.out.println(Arrays.toString(c));  //{true,false}
        Arrays.fill(c, false);
        System.out.println(Arrays.toString(c));  //{false,false}
        Arrays.fill(c, 0, 1, true);
        System.out.println(Arrays.toString(c));  //{true,false}
        
        String[] d = {"a","b","c","d","e","f"};
        System.out.println(Arrays.toString(d));  //{a,b,c,d,e,f}
        Arrays.fill(d, 1, 2, "HelloWorld");
        System.out.println(Arrays.toString(d));  //{a,HelloWorld,c,d,e,f}
        
    }
}

 

Java-Arrays类-fill()方法详解

标签:false   bool   str   包括   hello   ati   static   var   class   

原文地址:http://www.cnblogs.com/xiaozuoliunian/p/7784008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!