Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
I am learning GoF Java Design Patterns and I want to see some real life examples of them. Can you guys point to some good usage of these Design Patterns.(preferably in Java's core libraries). Thank you
In my quest to correctly grasp Interface best practices, I have noticed declarations such as: List<String> myList = new ArrayList<String>(); instead of ArrayList<String> myList = new ArrayList<String>(); -To my understanding the reason is because it allows flexibility in case one day you do not want to implement an ArrayList but maybe another type of list. With t...
From an online notes, I read the following java code snippet for reversing a string, which is claimed to have quadratic time complexity. It seems to me that the “for” loop for i just iterates the whole length of s. How does it cause a quadratic time complexity? public static String reverse(String s) { String rev = new String(); for (int i = (s.length()-1); i>=0; i--) { rev = rev.a...
I have a simple, general question regarding a real small issue that bothers me: I'm printing a list of elements on the fly, so I don't have prior knowledge about the number of printed elements. I want a simple format where the elements are separated by a comma (elem1, elem2...) or something similar. Now, if I use a simple loop like: while(elements to check) { if (elem should be printed) { ...
I found String.replaceAll() in Java with regular expression underlying. It works fine in short string. But in case of long string, I need a more efficient algorithm instead of String.replaceAll(). Anyone could give advice? Thanks!
in matcher.replace method,only has: replaceFirst() and replaceAll() two methods i want limit replace 3 times,how to do? example: String content="aaaaaaaaaa"; i want to get result is: "bbbaaaaaaa" my code: import java.util.regex.Matcher; import java.util.regex.Pattern; public class T1 { public static void main(String[] args) { String content="aaaaaaaaaa"; Pattern patte...
Possible Duplicate: Is there a way to say “method returns this” in Java? I'd like to define an interface in Java with a method whose return type is defined to be the implementing object's type. interface I { TYPE doSomething(); } class A implements I { @Override A doSomething() { return this; } } class B implements I { @Override B doSomething() ...
Hmmm. I'm trying to write a class that accepts bytes, and would like to implement a well-known interface for this purpose. java.io.OutputStream is an abstract class, not an interface (why???) and that makes me nervous, as I don't know what the consequences are of extending it. If there are no consequences, it should have been an interface. Otherwise it makes me think that it defines equals() a...
  /*
   * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Sun designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Sun in the LICENSE file that accompanied this code.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * version 2 for more details (a copy is included in the LICENSE file that
  * accompanied this code).
  *
  * You should have received a copy of the GNU General Public License version
  * 2 along with this work; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  * CA 95054 USA or visit www.sun.com if you need additional information or
  * have any questions.
  */
 
 package java.lang;
 
An object to which char sequences and values can be appended. The Appendable interface must be implemented by any class whose instances are intended to receive formatted output from a java.util.Formatter.

The characters to be appended should be valid Unicode characters as described in Unicode Character Representation. Note that supplementary characters may be composed of multiple 16-bit char values.

Appendables are not necessarily safe for multithreaded access. Thread safety is the responsibility of classes that extend and implement this interface.

Since this interface may be implemented by existing classes with different styles of error handling there is no guarantee that errors will be propagated to the invoker.

Since:
1.5
 
 public interface Appendable {

    
Appends the specified character sequence to this Appendable.

Depending on which class implements the character sequence csq, the entire sequence may not be appended. For instance, if csq is a java.nio.CharBuffer then the subsequence to append is defined by the buffer's position and limit.

Parameters:
csq The character sequence to append. If csq is null, then the four characters "null" are appended to this Appendable.
Returns:
A reference to this Appendable
Throws:
java.io.IOException If an I/O error occurs
 
     Appendable append(CharSequence csqthrows IOException;

    
Appends a subsequence of the specified character sequence to this Appendable.

An invocation of this method of the form out.append(csq, start, end) when csq is not null, behaves in exactly the same way as the invocation

     out.append(csq.subSequence(start, end)) 

Parameters:
csq The character sequence from which a subsequence will be appended. If csq is null, then characters will be appended as if csq contained the four characters "null".
start The index of the first character in the subsequence
end The index of the character following the last character in the subsequence
Returns:
A reference to this Appendable
Throws:
IndexOutOfBoundsException If start or end are negative, start is greater than end, or end is greater than csq.length()
java.io.IOException If an I/O error occurs
    Appendable append(CharSequence csqint startint endthrows IOException;

    
Appends the specified character to this Appendable.

Parameters:
c The character to append
Returns:
A reference to this Appendable
Throws:
java.io.IOException If an I/O error occurs
    Appendable append(char cthrows IOException;
New to GrepCode? Check out our FAQ X