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:Main.java

public static void main(String[] argv) {
    JColorChooser chooser = new JColorChooser();
    AbstractColorChooserPanel[] oldPanels = chooser.getChooserPanels();
    for (int i = 0; i < oldPanels.length; i++) {
        String clsName = oldPanels[i].getClass().getName();
        if (clsName.equals("javax.swing.colorchooser.DefaultSwatchChooserPanel")) {
            chooser.removeChooserPanel(oldPanels[i]);
        } else if (clsName.equals("javax.swing.colorchooser.DefaultRGBChooserPanel")) {
            chooser.removeChooserPanel(oldPanels[i]);
        } else if (clsName.equals("javax.swing.colorchooser.DefaultHSBChooserPanel")) {
            chooser.removeChooserPanel(oldPanels[i]);
        }/*from  ww w. j ava  2 s  .  c  o  m*/
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    Scanner conin = new Scanner(System.in);

    int count = 0;
    double sum = 0.0;

    System.out.println("Enter numbers to average.");

    while (conin.hasNext()) {
        if (conin.hasNextDouble()) {
            sum += conin.nextDouble();//  w ww  .  j a  v  a  2 s.co m
            count++;
        } else {
            String str = conin.next();
            if (str.equals("done"))
                break;
            else {
                System.out.println("Data format error.");
                return;
            }
        }
    }

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

From source file:Main.java

public static void main(String[] args) {
    File f = new File("c:/test");
    FilenameFilter fileNameFilter = new FilenameFilter() {
        @Override//from   w w w  .  jav  a 2s .c o m
        public boolean accept(File dir, String name) {
            if (name.lastIndexOf('.') > 0) {
                int lastIndex = name.lastIndexOf('.');
                String str = name.substring(lastIndex);
                if (str.equals(".txt")) {
                    return true;
                }
            }
            return false;
        }
    };
    File[] paths = f.listFiles(fileNameFilter);
    for (File path : paths) {
        System.out.println(path);
    }
}

From source file:MainClass.java

static public void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);/* ww  w  . ja  va 2 s  .co  m*/
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse("y.xml");

    NodeList configs = doc.getElementsByTagName("C");
    for (int i = 0; i < configs.getLength(); i++) {
        Element config = (Element) configs.item(i);
        String runMode = config.getAttribute("r").trim();
        if (runMode.equals("test")) {
            NodeList connectionURLs = config.getElementsByTagName("URL");
            System.out.println(connectionURLs.item(0).getNodeName() + "="
                    + connectionURLs.item(0).getFirstChild().getNodeValue());
            return;
        }
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    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);
        }//from   w w  w . ja  va2 s .c  o m
        if (ze.isDirectory()) {
            System.out.println(name + " is a directory");
        }
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String source = "<p xmlns='http://www.java2s.com/nfe' versao='2.00'></p>";

    XPathFactory xPathFactory = XPathFactory.newInstance();
    XPath xPath = xPathFactory.newXPath();

    NamespaceContext context = new NamespaceContext() {
        String PREFIX = "nfe";
        String URI = "http://www.java2s.com/nfe";

        @Override/*from   w w  w.j a va 2  s. c  o m*/
        public String getNamespaceURI(String prefix) {
            return (PREFIX.equals(prefix)) ? URI : XMLConstants.NULL_NS_URI;
        }

        @Override
        public String getPrefix(String namespaceUri) {
            return (URI.equals(namespaceUri)) ? PREFIX : XMLConstants.DEFAULT_NS_PREFIX;
        }

        @Override
        public Iterator getPrefixes(String namespaceUri) {
            return Collections.singletonList(this.getPrefix(namespaceUri)).iterator();
        }
    };
    xPath.setNamespaceContext(context);
    InputSource inputSource = new InputSource(new StringReader(source));
    String versao = xPath.evaluate("//nfe:p/@versao", inputSource);
    System.out.println(versao.toString());
}

From source file:MainClass.java

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

    JarFile jf = new JarFile(args[0]);
    Enumeration e = jf.entries();
    while (e.hasMoreElements()) {
        JarEntry je = (JarEntry) e.nextElement();
        String name = je.getName();

        long crc = je.getCrc();
        System.out.println("Its CRC is " + crc);
        String comment = je.getComment();
        if (comment != null && !comment.equals("")) {
            System.out.println(comment);
        }//www.jav a 2s  . c o  m
        if (je.isDirectory()) {
            System.out.println(name + " is a directory");
        }

    }
}

From source file:Main.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 w  w  . ja  v a  2 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:Main.java

public static void main(String[] args) {
    String s1 = "Hello World";
    String s2 = new String("Hello World");

    if (s1.equals(s2)) {
        System.out.println("String is equal");
    } else {/*  w  ww .  ja  v  a 2  s . c o  m*/
        System.out.println("String is unequal");
    }
    if (s1 == s2) {
        System.out.println("String is equal");
    } else {
        System.out.println("String is unequal");
    }
}

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();/*w ww. j  a v a 2  s .  co  m*/

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

    Scanner src = new Scanner(fin);

    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);
}