List of usage examples for java.lang String trim
public String trim()
From source file:Main.java
public static void main(String[] args) { System.out.println("Enter a string"); Scanner input = new Scanner(System.in); String s1 = input.nextLine(); s1 = s1.trim(); int howLong = s1.length(); for (int counter = 0; counter < howLong; counter++) { char ch = s1.charAt(counter); System.out.print(ch);//from w w w . j ava 2 s. c o m } }
From source file:example.ToCommonsNotBlank.java
public static void main(String[] args) { String s = ""; boolean a = s != null && s.trim().length() > 0; boolean b = s != null && !s.trim().isEmpty(); }
From source file:example.ToCommonsBlank.java
public static void main(String[] args) { String s = ""; boolean a = s == null || s.trim().length() == 0; boolean b = s == null || s.trim().isEmpty(); boolean c = s != null && s.trim().length() == 0; boolean d = s != null && s.trim().isEmpty(); }
From source file:Main.java
public static void main(String[] args) { String str = " this is a test "; String strTrimmed = str.trim(); System.out.println(">" + str + "<"); System.out.println(">" + strTrimmed + "<"); }
From source file:Main.java
public static void main(String[] args) { String text = " t "; System.out.println("Result: " + text.trim()); }
From source file:MainClass.java
public static void main(String[] arg) { String sample = " This is a string "; String result = sample.trim(); System.out.println(">" + sample + "<"); System.out.println(">" + result + "<"); }
From source file:Main.java
public static void main(String[] args) throws Exception { ZipFile zip = new ZipFile(new File("sample.zip")); for (Enumeration e = zip.entries(); e.hasMoreElements();) { ZipEntry entry = (ZipEntry) e.nextElement(); System.out.println("File name: " + entry.getName() + "; size: " + entry.getSize() + "; compressed size: " + entry.getCompressedSize()); InputStream is = zip.getInputStream(entry); InputStreamReader isr = new InputStreamReader(is); char[] buffer = new char[1024]; while (isr.read(buffer, 0, buffer.length) != -1) { String s = new String(buffer); System.out.println(s.trim()); }/*w w w . j a va 2s.c om*/ } }
From source file:Main.java
public static void main(String[] argv) { String str = " java 2 s.com "; System.out.println(">" + str + "<"); str = str.trim(); System.out.println(">" + str + "<"); }
From source file:Main.java
public static void main(String[] args) throws Exception { SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); parser.parse(new File("test.xml"), new DefaultHandler() { @Override/*from w w w . j a va 2s. co m*/ public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { if (qName.equals("passenger")) { System.out.println("id = " + atts.getValue(0)); } } @Override public void endElement(String uri, String localName, String qName) throws SAXException { } @Override public void characters(char[] ch, int start, int length) throws SAXException { String text = new String(ch, start, length); if (!text.trim().isEmpty()) { System.out.println("name " + text); } } }); }
From source file:com.game.GameLauncherApplication.java
public static void main(String[] args) throws Exception { // System.exit is common for Batch applications since the exit code can be used to // drive a workflow // System.exit(SpringApplication.exit(SpringApplication.run( // SampleBatchApplication.class, args))); String s = "Y"; while ("Y".equalsIgnoreCase(s.trim())) { ticTacToeGame.startGame();//from w w w .ja v a2 s . c o m System.out.println(" Do you want to play more to Play more enter Y "); BufferedReader BR = new BufferedReader(new InputStreamReader(System.in)); s = BR.readLine(); if (s != null && !s.isEmpty()) { s = s.trim(); } } }