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) throws Exception {
    Socket t = new Socket("127.0.0.1", 7);
    DataInputStream dis = new DataInputStream(t.getInputStream());
    PrintStream ps = new PrintStream(t.getOutputStream());
    ps.println("Hello");
    String str = dis.readUTF();
    if (str.equals("Hello"))
        System.out.println("Alive!");
    else/*from w  w  w.j  a va 2 s .c om*/
        System.out.println("Dead");
    t.close();
}

From source file:MainClass.java

public static void main(String[] arg) {

    String a = "a";
    String b = "a";

    if (a.equals(b)) {
        System.out.println("a==b");
    } else {//from w  w  w.j  a va 2s  . c  o  m
        System.out.println("a!=b");
    }
}

From source file:MainClass.java

public static void main(String[] args) {

    String s1 = "Java";
    String s2 = "Java";
    if (s1.equals(s2)) {
        System.out.println("==");
    }/* w  ww  .ja v a  2  s .  c om*/

}

From source file:Main.java

public static void main(String args[]) {
    List<String> list = new ArrayList<String>();

    list.add("A");
    list.add("B");
    list.add("C");
    list.add("C");
    list.add("C");
    list.add("C");
    list.add("C");

    for (String s : list) {
        if (s.equals("B")) {
            list.remove("B");
        }//from   w  ww. j  av  a  2  s  .  c om
        System.out.println(s);
    }
}

From source file:Test.java

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

    AsynchronousSocketChannel client = AsynchronousSocketChannel.open();
    InetSocketAddress address = new InetSocketAddress("localhost", 5000);

    Future<Void> future = client.connect(address);
    System.out.println("Client: Waiting for the connection to complete");
    future.get();/*w  w  w. j  a  v  a2s.c  o  m*/

    String message = "";
    while (!message.equals("quit")) {
        System.out.print("Enter a message: ");
        Scanner scanner = new Scanner(System.in);
        message = scanner.nextLine();
        System.out.println("Client: Sending ...");
        ByteBuffer buffer = ByteBuffer.wrap(message.getBytes());
        System.out.println("Client: Message sent: " + new String(buffer.array()));
        client.write(buffer);
    }
}

From source file:Gesture.java

public static void main(String[] args) {
    String choice = "S";

    if (choice.equals("S")) {
        generateDraw(Gesture.scissors);//from   w w w .j  a  va 2  s. c o m
    } else if (choice.equals("R")) {
        generateDraw(Gesture.rock);
    } else if (choice.equals("P")) {
        generateDraw(Gesture.paper);
    }

}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    InetAddress server = InetAddress.getByName("localhost");
    BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
    DatagramSocket theSocket = new DatagramSocket();
    while (true) {
        String theLine = userInput.readLine();
        if (theLine.equals("."))
            break;
        byte[] data = theLine.getBytes();
        DatagramPacket theOutput = new DatagramPacket(data, data.length, server, 99999);
        theSocket.send(theOutput);//w  ww. j a v a  2  s.c  om
    }

}

From source file:Main.java

public static void main(String[] args) {
    Console console = System.console();
    if (console != null) {
        console.printf("Console is  available.%n");
    } else {//from  ww w  . j  a va2 s.co m
        System.out.println("Console is  not  available.%n");
        return; // A console is not available
    }
    String userName = console.readLine("User Name: ");
    char[] passChars = console.readPassword("Password: ");
    String passString = new String(passChars);
    if (passString.equals("letmein")) {
        console.printf("Hello %s", userName);
    } else {
        console.printf("Invalid  password");
    }
}

From source file:Main.java

public static void main(String args[]) {
    ArrayList<String> list = new ArrayList<String>();

    list.add("A");
    list.add("B");
    list.add("C");
    list.add("C");
    list.add("C");
    list.add("C");
    list.add("C");
    list.add("C");

    for (Iterator<String> iter = list.iterator(); iter.hasNext();) {
        String s = iter.next();
        if (s.equals("B")) {
            iter.remove();//from  ww  w  . j  a  va  2  s.  co  m
        } else {
            System.out.println(s);
        }
    }

    for (String s : list) {
        System.out.println(s);
    }
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    String hostname = "localhost";

    Socket theSocket = new Socket(hostname, 7);
    BufferedReader networkIn = new BufferedReader(new InputStreamReader(theSocket.getInputStream()));
    BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(theSocket.getOutputStream());
    System.out.println("Connected to echo server");

    while (true) {
        String theLine = userIn.readLine();
        if (theLine.equals("."))
            break;
        out.println(theLine);/*from  ww  w .j  a  v  a 2s . c  om*/
        out.flush();
        System.out.println(networkIn.readLine());
    }
    networkIn.close();
    out.close();
}