Example usage for java.lang String equals

List of usage examples for java.lang String equals

Introduction

In this page you can find the example usage for java.lang String equals.

Prototype

public boolean equals(Object anObject) 

Source Link

Document

Compares this string to the specified object.

Usage

From source file:MainClass.java

public static void main(String args[]) throws IOException {
    int count = 0;
    double sum = 0.0;

    FileWriter fout = new FileWriter("test.txt");

    fout.write("2, 3.4,    5,6, 7.4, 9.1, 10.5, done");
    fout.close();//from w  ww . jav  a2  s .  c o m

    FileReader fin = new FileReader("Test.txt");

    Scanner src = new Scanner(fin);

    src.useDelimiter(", *");

    while (src.hasNext()) {
        if (src.hasNextDouble()) {
            sum += src.nextDouble();
            count++;
        } else {
            String str = src.next();
            if (str.equals("done"))
                break;
            else {
                System.out.println("File format error.");
                return;
            }
        }
    }

    fin.close();
    System.out.println("Average is " + sum / count);
}

From source file:org.eclipse.swt.snippets.Snippet33.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 33");
    shell.open();/*from  w  w  w .jav a  2  s.  c  o m*/
    DirectoryDialog dialog = new DirectoryDialog(shell);
    String platform = SWT.getPlatform();
    dialog.setFilterPath(platform.equals("win32") ? "c:\\" : "/");
    System.out.println("RESULT=" + dialog.open());
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:com.bitsofproof.supernode.main.Main.java

public static void main(String[] args) throws Exception {
    log.info("bitsofproof supernode (c) 2013 bits of proof zrt.");
    log.trace("Spring context setup");

    if (args.length == 0) {
        System.err.println(//from  www  .  jav  a 2 s. c o m
                "Usage: java com.bitsofproof.main.Main profile [profile...] -- [args...] [options...]");
        return;
    }

    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    List<String> a = new ArrayList<String>();
    boolean profiles = true;
    for (String s : args) {
        if (s.equals("--")) {
            profiles = false;
        } else {
            if (profiles) {
                log.info("Loading profile: " + s);
                ctx.getEnvironment().addActiveProfile(s);
            } else {
                a.add(s);
            }
        }
    }
    ctx.load("classpath:context/server.xml");
    ctx.load("classpath:context/*-profile.xml");
    ctx.refresh();
    ctx.getBean(App.class).start(a.toArray(new String[0]));
}

From source file:org.eclipse.swt.snippets.Snippet72.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Snippet 72");
    shell.open();/*from   w  w w  .j ava 2 s .c  o  m*/
    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
    String[] filterNames = new String[] { "Image Files", "All Files (*)" };
    String[] filterExtensions = new String[] { "*.gif;*.png;*.xpm;*.jpg;*.jpeg;*.tiff", "*" };
    String filterPath = "/";
    String platform = SWT.getPlatform();
    if (platform.equals("win32")) {
        filterNames = new String[] { "Image Files", "All Files (*.*)" };
        filterExtensions = new String[] { "*.gif;*.png;*.bmp;*.jpg;*.jpeg;*.tiff", "*.*" };
        filterPath = "c:\\";
    }
    dialog.setFilterNames(filterNames);
    dialog.setFilterExtensions(filterExtensions);
    dialog.setFilterPath(filterPath);
    dialog.setFileName("myfile");
    System.out.println("Save to: " + dialog.open());
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:MainClass.java

public static void main(String[] a) {
    JFrame frame = new JFrame("JFileChooser Popup");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JFileChooser fileChooser = new JFileChooser(".");
    fileChooser.setControlButtonsAreShown(false);
    frame.add(fileChooser, BorderLayout.CENTER);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JFileChooser theFileChooser = (JFileChooser) actionEvent.getSource();
            String command = actionEvent.getActionCommand();
            if (command.equals(JFileChooser.APPROVE_SELECTION)) {
                File selectedFile = theFileChooser.getSelectedFile();
                System.out.println(selectedFile.getParent());
                System.out.println(selectedFile.getName());
            } else if (command.equals(JFileChooser.CANCEL_SELECTION)) {
                System.out.println(JFileChooser.CANCEL_SELECTION);
            }/*from   ww w . j  ava  2  s.  c o  m*/
        }
    };
    fileChooser.addActionListener(actionListener);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    String apple = new String("Apple");
    String orange = new String("Orange");
    System.out.println(apple.equals(orange));
    System.out.println(apple.equals(apple));
    System.out.println(apple == apple);
    System.out.println(apple == orange);
    System.out.println(apple.compareTo(apple));
    System.out.println(apple.compareTo(orange));
}

From source file:MainClass.java

public static void main(String[] args) {

    try {// ww  w  .  ja  v  a  2  s .c o  m
        ZipFile zf = new ZipFile("your.zip");
        Enumeration e = zf.entries();
        while (e.hasMoreElements()) {
            ZipEntry ze = (ZipEntry) e.nextElement();
            String name = ze.getName();

            long crc = ze.getCrc();
            System.out.println("Its CRC is " + crc);

            String comment = ze.getComment();
            if (comment != null && !comment.equals("")) {
                System.out.println(comment);
            }
            if (ze.isDirectory()) {
                System.out.println(name + " is a directory");
            }
        }
    } catch (IOException ex) {
        System.err.println(ex);
    }
}

From source file:Main.java

public static void main(String[] args) {
    String str1 = new String("JAVA");
    String str2 = new String("java");

    System.out.println(str1.equals("JAVA"));

    System.out.println(str1.equals(str2));

    System.out.println(str1.equalsIgnoreCase(str2));
}

From source file:com.linkedin.pinot.broker.broker.BrokerServerBuilderTest.java

public static void main(String[] args) throws Exception {
    PropertiesConfiguration config = new PropertiesConfiguration(
            new File(BrokerServerBuilderTest.class.getClassLoader().getResource("broker.properties").toURI()));
    final BrokerServerBuilder bld = new BrokerServerBuilder(config, null, null, null);
    bld.buildNetwork();/* w  ww  . j av  a2s . c om*/
    bld.buildHTTP();
    bld.start();

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                bld.stop();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    while (true) {
        String command = br.readLine();
        if (command.equals("exit")) {
            bld.stop();
        }
    }

}

From source file:Main.java

public static void main(String[] a) {
    final JTextField textField = new JTextField(5);

    textField.addFocusListener(new FocusListener() {
        public void focusGained(FocusEvent e) {
        }//from w w w .  j  a v a2s  . c  o m

        public void focusLost(FocusEvent e) {
            if (!e.isTemporary()) {
                String content = textField.getText();
                if (!content.equals("a")) {
                    System.out.println("illegal value! " + content);
                    SwingUtilities.invokeLater(new FocusGrabber(textField));
                }
            }
        }
    });
    JFrame frame = new JFrame();
    frame.add(textField, BorderLayout.CENTER);
    frame.setSize(300, 300);
    frame.setVisible(true);

}