Example usage for java.util Arrays fill

List of usage examples for java.util Arrays fill

Introduction

In this page you can find the example usage for java.util Arrays fill.

Prototype

public static void fill(Object[] a, Object val) 

Source Link

Document

Assigns the specified Object reference to each element of the specified array of Objects.

Usage

From source file:Main.java

public static void main(String[] args) {
    char c = 'x';
    int length = 10;

    // creates char array with 10 elements
    char[] chars = new char[length];

    // fill each element of chars array with 'x'
    Arrays.fill(chars, c);

    // print out the repeated 'x'
    System.out.println(String.valueOf(chars));
}

From source file:Main.java

public static void main(String[] args) {

    // initializing double array
    double arr[] = new double[] { 1.2, 5.6, 3.4, 2.3, 6.7 };

    System.out.println(Arrays.toString(arr));

    // using fill for placing 1.2
    Arrays.fill(arr, 1.2);

    System.out.println(Arrays.toString(arr));
}

From source file:Main.java

public static void main(String[] args) {

    // initializing Object array
    Object arr[] = new Object[] { 1.5, 5.6, 4.5, 2.3, 6.7 };

    System.out.println(Arrays.toString(arr));

    // using fill for placing 12.2
    Arrays.fill(arr, 12.2);

    System.out.println(Arrays.toString(arr));
}

From source file:Main.java

public static void main(String[] args) {

    // initializing byte array
    byte arr[] = new byte[] { 1, 6, 3 };

    System.out.println(Arrays.toString(arr));

    // using fill for placing 8
    // converting int to byte
    Arrays.fill(arr, (byte) 8);

    System.out.println(Arrays.toString(arr));
}

From source file:Main.java

public static void main(String[] args) {
    Console console = System.console();
    String username = console.readLine("Username: ");
    char[] password = console.readPassword("Password: ");

    if (username.equals("admin") && String.valueOf(password).equals("secret")) {
        console.printf("Welcome to Java Application %1$s.\n", username);

        Arrays.fill(password, ' ');
    } else {/*from  w  w  w.  ja  v  a2 s  .  c om*/
        console.printf("Invalid username or password.\n");
    }
}

From source file:Main.java

  public static void main(String[] argv) throws Exception {

  byte[] byteArr = new byte[10];
  byte byteFillValue = (byte) 0xFF;
  Arrays.fill(byteArr, byteFillValue);
}

From source file:Main.java

public static void main(String[] args) {
    Console console = System.console();

    if (console == null) {
        System.out.println("Console is not available");
        System.exit(1);/*from   ww w .j a  va2s  .  c  om*/
    }

    char[] password = "java2s.com".toCharArray();

    char[] passwordEntered = console.readPassword("Enter password: ");

    if (Arrays.equals(password, passwordEntered)) {
        System.out.println("\n Access granted \n");
        Arrays.fill(password, ' ');
        Arrays.fill(passwordEntered, ' ');
        System.out.println("OK ...");
    } else {
        System.out.println("Access denied");
        System.exit(1);
    }
}

From source file:PasswordPromptingDemo.java

public static void main(String[] args) {
    Console console = System.console();

    if (console == null) {
        System.out.println("Console is not available");
        System.exit(1);//from  w  w w .jav  a 2s  .c o  m
    }

    char[] password = "mustang".toCharArray();

    char[] passwordEntered = console.readPassword("Enter password: ");

    if (Arrays.equals(password, passwordEntered)) {
        System.out.println("\n Access granted \n");
        Arrays.fill(password, ' ');
        Arrays.fill(passwordEntered, ' ');
        System.out.println("OK ...");
    } else {
        System.out.println("Access denied");
        System.exit(1);
    }
}

From source file:Main.java

  public static void main(String[] argv) throws Exception {

  char[] charArr = new char[10];
  char charFillValue = 'c';
  Arrays.fill(charArr, charFillValue);
}

From source file:Main.java

  public static void main(String[] argv) throws Exception {

  short[] shortArr = new short[10];
  short shortFillValue = 2;
  Arrays.fill(shortArr, shortFillValue);
}