Example usage for java.util List clear

List of usage examples for java.util List clear

Introduction

In this page you can find the example usage for java.util List clear.

Prototype

void clear();

Source Link

Document

Removes all of the elements from this list (optional operation).

Usage

From source file:Main.java

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

    List<String> list = new ArrayList<String>();
    list.add("A");
    list.add("B");
    list.add("C");
    list.clear();

    System.out.println(list);/*  www .  jav  a  2 s .  c o  m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    List list1 = new ArrayList();
    List list2 = new ArrayList();

    list1.addAll(list2);/*  w w  w .  ja  v a2  s. c  om*/

    list1.removeAll(list2);

    list1.retainAll(list2);

    list1.clear();

    int newSize = 2;
    list1.subList(newSize, list1.size()).clear();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    List<String> list1 = new ArrayList();
    List<String> list2 = new ArrayList();

    list1.addAll(list2);/*from   w  ww  .jav a2s .  co m*/

    list1.removeAll(list2);

    list1.retainAll(list2);

    list1.clear();

    int newSize = 2;
    list1.subList(newSize, list1.size()).clear();
}

From source file:MainClass.java

public static void main(String[] a) {

    List list = new ArrayList();
    list.add("A");

    List list2 = ((List) ((ArrayList) list).clone());

    System.out.println(list);/*from w w  w. j a v a 2  s . c om*/
    System.out.println(list2);

    list.clear();

    System.out.println(list);
    System.out.println(list2);
}

From source file:Main.java

public static void main(String[] a) {

    List<String> list = new ArrayList<String>();
    list.add("A");

    List list2 = ((List) ((ArrayList) list).clone());

    System.out.println(list);// www  . j  a v  a2  s  .c o  m
    System.out.println(list2);

    list.clear();

    System.out.println(list);
    System.out.println(list2);
}

From source file:edu.harvard.med.screensaver.io.screens.StudyCreator.java

@SuppressWarnings("static-access")
public static void main(String[] args) {
    final CommandLineApplication app = new CommandLineApplication(args);

    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("first name")
            .withLongOpt("lead-screener-first-name").create("lf"));
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("last name")
            .withLongOpt("lead-screener-last-name").create("ll"));
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("email")
            .withLongOpt("lead-screener-email").create("le"));

    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("first name")
            .withLongOpt("lab-head-first-name").create("hf"));
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("last name")
            .withLongOpt("lab-head-last-name").create("hl"));
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("email")
            .withLongOpt("lab-head-email").create("he"));

    List<String> desc = new ArrayList<String>();
    for (ScreenType t : EnumSet.allOf(ScreenType.class))
        desc.add(t.name());/*  w  w  w.j  a v  a 2 s .co  m*/
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("screen type")
            .withLongOpt("screen-type").withDescription(StringUtils.makeListString(desc, ", ")).create("y"));
    desc.clear();
    for (StudyType t : EnumSet.allOf(StudyType.class))
        desc.add(t.name());
    app.addCommandLineOption(OptionBuilder.hasArg().isRequired().withArgName("study type")
            .withLongOpt("study-type").withDescription(StringUtils.makeListString(desc, ", ")).create("yy"));
    app.addCommandLineOption(
            OptionBuilder.hasArg().isRequired().withArgName("summary").withLongOpt("summary").create("s"));
    app.addCommandLineOption(
            OptionBuilder.hasArg().isRequired().withArgName("title").withLongOpt("title").create("t"));
    app.addCommandLineOption(
            OptionBuilder.hasArg().withArgName("protocol").withLongOpt("protocol").create("p"));
    app.addCommandLineOption(
            OptionBuilder.hasArg().isRequired().withArgName("#").withLongOpt("facilityId").create("i"));
    app.addCommandLineOption(OptionBuilder.hasArg(false).withLongOpt("replace")
            .withDescription("replace an existing Screen with the same facilityId").create("r"));

    app.addCommandLineOption(OptionBuilder.withLongOpt("key-input-by-wellkey")
            .withDescription("default value is to key by reagent vendor id").create("keyByWellId"));
    app.addCommandLineOption(OptionBuilder.withLongOpt("key-input-by-facility-id")
            .withDescription("default value is to key by reagent vendor id").create("keyByFacilityId"));
    app.addCommandLineOption(OptionBuilder.withLongOpt("key-input-by-compound-name")
            .withDescription("default value is to key by reagent vendor id").create("keyByCompoundName"));
    app.addCommandLineOption(OptionBuilder.withDescription(
            "optional: pivot the input col/rows so that the AT names are in Col1, and the AT well_id/rvi's are in Row1")
            .withLongOpt("annotation-names-in-col1").create("annotationNamesInCol1"));
    app.addCommandLineOption(OptionBuilder.hasArg().withArgName("file").withLongOpt("data-file").create("f"));

    app.addCommandLineOption(OptionBuilder.withArgName("parseLincsSpecificFacilityID")
            .withLongOpt("parseLincsSpecificFacilityID").create("parseLincsSpecificFacilityID"));
    app.processOptions(/* acceptDatabaseOptions= */true, /* acceptAdminUserOptions= */true);
    execute(app);
}

From source file:com.microsoft.gittf.client.clc.Main.java

public static void main(String[] args) {
    // Configure logging, use the standard TFS SDK logging.
    System.setProperty("teamexplorer.application", ProductInformation.getProductName()); //$NON-NLS-1$
    LoggingConfiguration.configure();//from  www  .ja v a  2  s.c  om

    final Log log = LogFactory.getLog(ProductInformation.getProductName());

    try {
        ArgumentCollection mainArguments = new ArgumentCollection();

        try {
            mainArguments = ArgumentParser.parse(args, ARGUMENTS,
                    ArgumentParserOptions.ALLOW_UNKNOWN_ARGUMENTS);
        } catch (ArgumentParserException e) {
            console.getErrorStream().println(e.getLocalizedMessage());
            console.getErrorStream().println(getUsage());
            System.exit(ExitCode.FAILURE);
        }

        if (mainArguments.contains("version")) //$NON-NLS-1$
        {
            console.getOutputStream().println(Messages.formatString("Main.ApplicationVersionFormat", //$NON-NLS-1$
                    ProductInformation.getProductName(), ProductInformation.getBuildNumber()));

            return;
        }

        /*
         * Special case "--help command" handling - convert to
         * "help command"
         */
        if (mainArguments.contains("help") && mainArguments.contains("command")) //$NON-NLS-1$ //$NON-NLS-2$
        {
            HelpCommand helpCommand = new HelpCommand();
            helpCommand.setArguments(ArgumentParser.parse(new String[] {
                    ((FreeArgumentCollection) mainArguments.getArgument("command")).getValues()[0] //$NON-NLS-1$                
            }, helpCommand.getPossibleArguments()));

            helpCommand.setConsole(console);
            helpCommand.run();
            return;
        } else if (mainArguments.contains("help") || !mainArguments.contains("command")) //$NON-NLS-1$ //$NON-NLS-2$
        {
            showHelp();
            return;
        }

        // Set the verbosity of the console from the arguments.
        if (mainArguments.contains("quiet")) //$NON-NLS-1$
        {
            console.setVerbosity(Verbosity.QUIET);
        } else if (mainArguments.contains("verbose")) //$NON-NLS-1$
        {
            console.setVerbosity(Verbosity.VERBOSE);
        }

        /*
         * Parse the free arguments into the command name and arguments to
         * pass to it. Add any unmatched arguments that were specified on
         * the command line before the argument. (eg, for
         * "git-tf --bare clone", we parsed the "--bare" as an unmatched
         * argument to the main command. We instead want to add the "--bare"
         * as an argument to "clone".)
         */
        String[] fullCommand = ((FreeArgumentCollection) mainArguments.getArgument("command")).getValues(); //$NON-NLS-1$
        String[] additionalArguments = mainArguments.getUnknownArguments();

        String commandName = fullCommand[0];
        String[] commandArgs = new String[additionalArguments.length + (fullCommand.length - 1)];

        if (additionalArguments.length > 0) {
            System.arraycopy(additionalArguments, 0, commandArgs, 0, additionalArguments.length);
        }

        if (fullCommand.length > 1) {
            System.arraycopy(fullCommand, 1, commandArgs, mainArguments.getUnknownArguments().length,
                    fullCommand.length - 1);
        }

        // Locate the specified command by name
        List<CommandDefinition> possibleCommands = new ArrayList<CommandDefinition>();

        for (CommandDefinition c : COMMANDS) {
            if (c.getName().equals(commandName)) {
                possibleCommands.clear();
                possibleCommands.add(c);
                break;
            } else if (c.getName().startsWith(commandName)) {
                possibleCommands.add(c);
            }
        }

        if (possibleCommands.size() == 0) {
            printError(Messages.formatString("Main.CommandNotFoundFormat", commandName, //$NON-NLS-1$
                    ProductInformation.getProductName()));
            System.exit(1);
        }

        if (possibleCommands.size() > 1) {
            printError(Messages.formatString("Main.AmbiguousCommandFormat", commandName, //$NON-NLS-1$
                    ProductInformation.getProductName()));

            for (CommandDefinition c : possibleCommands) {
                printError(Messages.formatString("Main.AmbiguousCommandListFormat", c.getName()), false); //$NON-NLS-1$
            }

            System.exit(1);
        }

        // Instantiate the command
        final CommandDefinition commandDefinition = possibleCommands.get(0);
        Command command = null;

        try {
            command = commandDefinition.getType().newInstance();
        } catch (Exception e) {
            printError(Messages.formatString("Main.CommandCreationFailedFormat", commandName)); //$NON-NLS-1$
            System.exit(1);
        }

        // Set the console
        command.setConsole(console);

        // Parse the arguments
        ArgumentCollection argumentCollection = null;

        try {
            argumentCollection = ArgumentParser.parse(commandArgs, command.getPossibleArguments());
        } catch (ArgumentParserException e) {
            Main.printError(e.getLocalizedMessage());
            Main.printError(getUsage(command));

            log.error("Could not parse arguments", e); //$NON-NLS-1$
            System.exit(1);
        }

        // Handle the --help argument directly
        if (argumentCollection.contains("help")) //$NON-NLS-1$
        {
            command.showHelp();
            System.exit(0);
        }

        // Set the verbosity of the console from the arguments.
        if (argumentCollection.contains("quiet")) //$NON-NLS-1$
        {
            console.setVerbosity(Verbosity.QUIET);
        } else if (argumentCollection.contains("verbose")) //$NON-NLS-1$
        {
            console.setVerbosity(Verbosity.VERBOSE);
        }

        command.setArguments(argumentCollection);

        System.exit(command.run());

    } catch (Exception e) {
        printError(e.getLocalizedMessage());
        log.warn(MessageFormat.format("Error executing command: {0}", getCommandLine(args)), e); //$NON-NLS-1$
    }
}

From source file:com.heliosapm.streams.collector.ds.pool.TestMQPool.java

/**
 * @param args/* w w w.j  a  va  2  s.  c om*/
 */
public static void main(String[] args) {
    try {
        log("Pool Test");
        log(TEST_PROPS);
        JMXHelper.fireUpJMXMPServer(1077);
        final Properties p = Props.strToProps(TEST_PROPS);
        log("Props:" + p);
        final GenericObjectPool<Object> pool = null;//(GenericObjectPool<Object>)PoolConfig.deployPool(p);
        pool.preparePool();
        log("Pool Deployed:" + pool.getNumIdle());
        final List<Object> objects = new ArrayList<Object>();
        for (int i = 0; i < 4; i++) {
            try {
                final Object o = pool.borrowObject();
                log("Borrowed:" + o);
                objects.add(o);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        log("Objects:" + objects.size());
        StdInCommandHandler.getInstance().registerCommand("close", new Runnable() {
            public void run() {
                for (Object o : objects) {
                    pool.returnObject(o);
                }
                objects.clear();
                try {
                    pool.close();
                } catch (Exception ex) {
                    ex.printStackTrace(System.err);
                }
            }
        }).run();
    } catch (Exception ex) {
        ex.printStackTrace(System.err);
    }

}

From source file:com.moss.veracity.core.Veracity.java

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

    File log4jConfigFile = new File("log4j.xml");

    if (log4jConfigFile.exists()) {
        DOMConfigurator.configureAndWatch(log4jConfigFile.getAbsolutePath(), 1000);
    }/*  w  w w .j  a v  a 2s.  c o  m*/

    final Log log = LogFactory.getLog(Veracity.class);

    File homeDir = new File(System.getProperty("user.home"));
    File currentDir = new File(System.getProperty("user.dir"));

    List<File> configLocations = new LinkedList<File>();
    configLocations.addAll(Arrays.asList(new File[] { new File("/etc/veracity.config"),
            new File(homeDir, ".veracity.config"), new File(currentDir, "config.xml") }));

    String customConfigFileProperty = System.getProperty("veracity.configFile");
    if (customConfigFileProperty != null) {
        configLocations.clear();
        configLocations.add(new File(customConfigFileProperty));
    }

    File configFile = null;

    Iterator<File> i = configLocations.iterator();
    while ((configFile == null || !configFile.exists()) && i.hasNext()) {
        configFile = i.next();
    }

    LaunchParameters parameters;

    if (!configFile.exists()) {
        if (log.isDebugEnabled()) {
            log.debug("Creating default config file at " + configFile.getAbsolutePath());
        }
        parameters = new LaunchParameters();
        parameters.save(configFile);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Loading parameters from config file at " + configFile.getAbsolutePath());
        }
        parameters = LaunchParameters.load(configFile);
    }

    parameters.readSystemProperties();

    new Veracity(parameters);
}

From source file:com.faces.controller.util.FaceRecognitionUtils.java

public static void main(String[] args) {
    String path = "H:\\MyWork\\facerecognition\\javacv-02385ce192fb\\facerecExample_ORL\\Cambridge_FaceDB\\s42\\";
    List<String> listOfimages = new ArrayList<>();

    File dir = new File(path);

    File[] arrFile = dir.listFiles();
    for (File file : arrFile) {
        listOfimages.add(file.getAbsolutePath());
    }//w  ww . j  a v  a2 s. c  om

    FaceRecognitionUtils utils = new FaceRecognitionUtils();
    utils.storeTraningData(1, listOfimages);

    listOfimages.clear();
    String path1 = "H:\\MyWork\\facerecognition\\javacv-02385ce192fb\\facerecExample_ORL\\Cambridge_FaceDB\\s41\\";
    listOfimages.add(path1 + File.separator + "35.jpg");

    utils.recognizeStudent(1, listOfimages);

}