Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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...
It seems to me that calling string.length() each time takes significantly longer than just accessing a variable.
StringBuffer sb1 = new StringBuffer("Java"); StringBuffer sb2 = new StringBuffer("Java"); System.out.println(sb1 == sb2); System.out.println(sb1.equals(sb2)); Here both are returning false. How is it possible?
I seek an example of applying a regular expression to a Java I/O stream that doesn't simply convert the stream to a string as I would like to preserve binary data. Most of the examples on the Internet focus on text data...
I'm reading in a file which I can't buffer all at once, as its size ranges from 256MB upto ~2GB in size. Once the file is opened, I read a chunk of it into a byte array, say 512 bytes, run a regex over it, and if the pattern is detected, my program makes a note of it. The problem I'm having is that my program is missing a lot of the locations in the file where it should be detecting the patte...
What is the difference between CharSequence[] and String[]?
In a program I am writing I am doing a lot of string manipulation. I am trying to increase performance and am wondering if using char arrays would show a decent performance increase. Any suggestions?
Why is CharSequence from the Java API an interface? What is the significance of this interface?
I'm having trouble creating a simple app, I created a variable that changes when you click a button, but I would like to know how to set my TextView to that variable. total is my TextView, and count is my variable. I am trying total.setText(count); I dont know how to tell it to just take the value of count and set the text to that. Any help would be greatly appreciated.
Why are interfaces useful? Actually, I have a [small] idea of why interfaces are useful/necessary but... What are [interesting or realistic] applications of interfaces?
I am trying to read a UTF8 string via a java.nio.ByteBuffer. The size is an unsinged int, which, of course, Java doesn't have. I have read the value into a long so that I have the value. The next issue I have is that I cannot create an array of bytes with the long, and casting he long back to an int will cause it to be signed. I also tried using limit() on the buffer, but again it works wit...
How can I convert a Java CharSequence to a String?
I am looking for XML/XHTML Java library/framework that can perform the following two tasks for me. Before going on few definitions: NodeOffset(Node node, int offset) marks some point in text node in the XML tree. nodeB, nodeI, nodeP are the corresponding Node instances of the below mentioned XHTML tree and nodeSpan is some newly created node (where Node is not necessarily org.w3c.dom.Node an...
Is there a Way to converte a Charsequence or a String to an Ingeter? CharSequence cs = "123"; int number = (int) cs; I'm a Noob. Solution: CharSequence cs = "123"; int number = Integer.parseInt(cs);
I have 40KB HTML page and I want to find certain patterns in it. I can read it by 1K buffer but I want to avoid situation that pattern that I'm searching would be split between two buffer reads. How to overcome this problem?
Possible Duplicate: String, StringBuffer, and StringBuilder What are common methods between String and StringBuffer? And what is the difference between string and string buffer?
one way to initialize charsequence[] is charsequence[] item = {"abc","def"}; but i don't want to initialize it this way. can someone please suggest some other way like the way we initialize string[] array... thanks
Here I am downloading a web-page source code then storing it in text file. Then I read that file and match it with a regex to search for a specific string. There is no compiler error. Exception in thread "main" java.lang.NoClassDefFoundError: java/lang/CharSequence Can anybody tell me Where I am wrong. java version "1.3.1_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01...
  /*
   * Copyright 2000-2003 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;


A CharSequence is a readable sequence of char values. This interface provides uniform, read-only access to many different kinds of char sequences. A char value represents a character in the Basic Multilingual Plane (BMP) or a surrogate. Refer to Unicode Character Representation for details.

This interface does not refine the general contracts of the Object.equals(java.lang.Object) and Object.hashCode() methods. The result of comparing two objects that implement CharSequence is therefore, in general, undefined. Each object may be implemented by a different class, and there is no guarantee that each class will be capable of testing its instances for equality with those of the other. It is therefore inappropriate to use arbitrary CharSequence instances as elements in a set or as keys in a map.

Author(s):
Mike McCloskey
Since:
1.4
Spec:
JSR-51
 
 
 public interface CharSequence {

    
Returns the length of this character sequence. The length is the number of 16-bit chars in the sequence.

Returns:
the number of chars in this sequence
 
     int length();

    
Returns the char value at the specified index. An index ranges from zero to length() - 1. The first char value of the sequence is at index zero, the next at index one, and so on, as for array indexing.

If the char value specified by the index is a surrogate, the surrogate value is returned.

Parameters:
index the index of the char value to be returned
Returns:
the specified char value
Throws:
IndexOutOfBoundsException if the index argument is negative or not less than length()
 
     char charAt(int index);

    
Returns a new CharSequence that is a subsequence of this sequence. The subsequence starts with the char value at the specified index and ends with the char value at index end - 1. The length (in chars) of the returned sequence is end - start, so if start == end then an empty sequence is returned.

Parameters:
start the start index, inclusive
end the end index, exclusive
Returns:
the specified subsequence
Throws:
IndexOutOfBoundsException if start or end are negative, if end is greater than length(), or if start is greater than end
 
    CharSequence subSequence(int startint end);

    
Returns a string containing the characters in this sequence in the same order as this sequence. The length of the string will be the length of this sequence.

Returns:
a string consisting of exactly this sequence of characters
    public String toString();
New to GrepCode? Check out our FAQ X