Java 8 String - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 String class.

This code example shows how to use the following methods:charAt, length, replaceAll, substring, valueOf
public class AbstractCodegenTestCaseOnAndroid extends TestCase {
 
    protected void invokeBoxMethod(String filePath, String expectedResult) throws Exception {
        try { 
            Class clazz;
            String packageName = filePath.replaceAll("\\\\|-|\\.|/", "_");
            clazz = Class.forName(packageName + "." + getPackageClassName(packageName));
            Method method;
            method = clazz.getMethod("box");
            assertEquals(expectedResult, method.invoke(null));
        } 
        catch (Throwable e) {
            throw new RuntimeException("File: " + filePath, e);
        } 
    } 
 
    public static String getPackageClassName(String packageName) {
        return Character.toUpperCase(packageName.charAt(0)) + packageName.substring(1, packageName.length()) + "Package";
    } 
} 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:equals
      // 
    } 
  } 
   
  public void start(BundleContext context) throws Exception{ 
    String propVal=new String("both");
    String propValue=context.getProperty("mosgi.jmxconsole.remotelogger.componentfilter");
    if (propValue!=null) {
      if (propValue.equals("treeonly") | propValue.equals("tableonly") | propValue.equals("both") | propValue.equals("none")) {
        propVal=propValue;
      }else { 
        propVal="both";
      } 
    } 
 
    if (propVal.equals("treeonly") | propVal.equals("both")) {
      context.registerService(CommonPlugin.class.getName(), new RemoteLogger_jtree(context), null);
    } 
    if (propVal.equals("tableonly") | propVal.equals("both")) {
      context.registerService(CommonPlugin.class.getName(), new RemoteLogger_jtable(), null);

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
	static public short fieldStaticS = 32767;
	static public int fieldStaticI = 2147483467;
	static public long fieldStaticJ = 2147483467;
	static public float fieldStaticF = 1.23456789f;
	static public double fieldStaticD = 1.23456789;
	static public String fieldStaticString = new String("helloworld");
 
	public boolean fieldZ = true;
	public byte fieldB = 127;
	public char fieldC = 'k';
	public short fieldS = 32767;
	public int fieldI = 2147483467;
	public long fieldJ = 2147483467;
	public float fieldF = 1.23456789f;
	public double fieldD = 1.23456789;
	public String fieldString = new String("helloworld");
 
    public BasicsTest() {} 
    public BasicsTest(byte fieldBVal) {
        fieldB = fieldBVal;
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:equals
        return majorVersion >= minVersion;
	} 
 
	public static int getDefaultMinVersion(String engine) {
 
		if (engine.equals(INTERNET_EXPLORER))
			// ie7 
			return 7; 
		if (engine.equals(OPERA))
			// opera 9 
			return 9; 
		if (engine.equals(FIREFOX))
			// firefox 5 
			return 5; 
		if (engine.equals(CHROME))
			// chrome 13 
			return 13; 
		if (engine.equals(SAFARI))
			// safari 5 
			return 5; 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:equals
   
  public void start(BundleContext context) throws Exception{ 
    String propVal=new String("both");
    String propValue=context.getProperty("mosgi.jmxconsole.remotelogger.componentfilter");
    if (propValue!=null) {
      if (propValue.equals("treeonly") | propValue.equals("tableonly") | propValue.equals("both") | propValue.equals("none")) {
        propVal=propValue;
      }else { 
        propVal="both";
      } 
    } 
 
    if (propVal.equals("treeonly") | propVal.equals("both")) {
      context.registerService(CommonPlugin.class.getName(), new RemoteLogger_jtree(context), null);
    } 
    if (propVal.equals("tableonly") | propVal.equals("both")) {
      context.registerService(CommonPlugin.class.getName(), new RemoteLogger_jtable(), null);
    } 
  } 
 
  public void stop(BundleContext context) {
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:charAt, equals
     
    public OutputStream _invoke(String method, InputStream _in, ResponseHandler reply) throws SystemException {
        try { 
            org.omg.CORBA_2_3.portable.InputStream in = 
                (org.omg.CORBA_2_3.portable.InputStream) _in;
            switch (method.charAt(5)) {
                case 69:  
                    if (method.equals("_get_EJBHome")) {
                        return _get_EJBHome(in, reply);
                    } 
                case 101:  
                    if (method.equals("remove")) {
                        return remove(in, reply);
                    } 
                case 104:  
                    if (method.equals("_get_handle")) {
                        return _get_handle(in, reply);
                    } 
                case 110:  
                    if (method.equals("isIdentical")) {

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:equals, length
     
    public OutputStream _invoke(String method, InputStream _in, ResponseHandler reply) throws SystemException {
        try { 
            org.omg.CORBA_2_3.portable.InputStream in = 
                (org.omg.CORBA_2_3.portable.InputStream) _in;
            switch (method.length()) {
                case 6:  
                    if (method.equals("create")) {
                        return create(in, reply);
                    } 
                case 15:  
                    if (method.equals("_get_homeHandle")) {
                        return _get_homeHandle(in, reply);
                    } 
                case 16:  
                    if (method.equals("_get_EJBMetaData")) {
                        return _get_EJBMetaData(in, reply);
                    } 
                case 24:  
                    if (method.equals("remove__java_lang_Object")) {

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
 
  public void setFromChar(final char[] seqString)
        throws ReadOnlyException, IllegalSymbolException 
  { 
    Edit ed = new Edit(1, length (), DNATools.createDNA(new String(seqString)));
    try { 
      symbols.edit(ed);
    } catch (ChangeVetoException e) {
      throw new ReadOnlyException ("cannot set sequence - readonly"); 
    } catch (IllegalAlphabetException e) {
      throw new Error ("internal error - unexpected exception: " + e);
    } 
  } 
 
  public void clear() 
  { 
  } 
   
    private void countSymbols() 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:indexOf, substring
        RealmService realmService = AuthenticationServiceDataHolder.getInstance().getRealmService();
        if (null != realmService) {
            try { 
                // Get tenant ID 
                int tenantID = 0;
                int domainNameSeparatorIndex = username.indexOf(DOMAIN_NAME_SEPARATOR);
                if (-1 != domainNameSeparatorIndex) { // Service case
                    String domainName = username.substring(domainNameSeparatorIndex + 1);
                    tenantID = realmService.getTenantManager().getTenantId(domainName);
                } 
 
                // Get Realm 
                userRealm = realmService.getTenantUserRealm(tenantID);
            } catch (org.wso2.carbon.user.api.UserStoreException e) {
                logger.warn("Error while getting tenant user realm for user " + username);
            } 
        } 
 
        return userRealm;
    } 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:equalsIgnoreCase
 
//ACTIONS DONE 
	public void actionPerformed(ActionEvent evt) {
		String cmd = evt.getActionCommand();
		if (cmd != null) {
			if (cmd.equalsIgnoreCase("Forums")) {
launchURL("http://TNS317.webs.com"); 
			} 
			if (cmd.equalsIgnoreCase("Vote")) {
launchURL("http://runelocus.com/toplist/index.php?action=vote&id=20385"); 
				 } 
			if (cmd.equalsIgnoreCase("Donate")) {
launchURL("http://TNS317.webs.com"); 
			} 
			if (cmd.equalsIgnoreCase("Exit")) {
				int i1;
				if((i1 = JOptionPane.showConfirmDialog(this, "Do you really want to exit the client - did you save?")) == 0)
					System.exit(0);
				return; 
			} 

6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 String Questions & Answers:

Other Java 8 String Examples

6:	public class SendMessageToDevice {
7:	
8:	  public static void main(String[] args) throws IOException {
9:	    // "Message to your device." is the message we will send to the Android app
10:	    int responseCode = MessageUtil.sendMessage(ServerConfiguration.AUTHENTICATION_TOKEN,

Read More

25:	        mCursor, // Pass in the cursor to bind to.
26:	        // Array of cursor columns to bind to.
27:	        new String[] { ContactsContract.Contacts._ID,
28:	            ContactsContract.Contacts.DISPLAY_NAME },
29:	        // Parallel array of which template objects to bind to those
-
38:	    // Run query
39:	    Uri uri = ContactsContract.Contacts.CONTENT_URI;
40:	    String[] projection = new String[] { ContactsContract.Contacts._ID,
41:	        ContactsContract.Contacts.DISPLAY_NAME };
42:	    String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '"
-
38:	    // Run query
39:	    Uri uri = ContactsContract.Contacts.CONTENT_URI;
40:	    String[] projection = new String[] { ContactsContract.Contacts._ID,
41:	        ContactsContract.Contacts.DISPLAY_NAME };
42:	    String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '"
-
40:	    String[] projection = new String[] { ContactsContract.Contacts._ID,
41:	        ContactsContract.Contacts.DISPLAY_NAME };
42:	    String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '"
43:	        + ("1") + "'";
44:	    String[] selectionArgs = null;
-
42:	    String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '"
43:	        + ("1") + "'";
44:	    String[] selectionArgs = null;
45:	    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
46:	        + " COLLATE LOCALIZED ASC";
-
43:	        + ("1") + "'";
44:	    String[] selectionArgs = null;
45:	    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
46:	        + " COLLATE LOCALIZED ASC";
47:

Read More

21:	    super.onCreate(savedInstanceState);
22:	    setContentView(R.layout.main);
23:	    wordList = new ArrayList<String>();
24:	    adapter = new ArrayAdapter<String>(this,
25:	        android.R.layout.simple_list_item_1, android.R.id.text1,
-
22:	    setContentView(R.layout.main);
23:	    wordList = new ArrayList<String>();
24:	    adapter = new ArrayAdapter<String>(this,
25:	        android.R.layout.simple_list_item_1, android.R.id.text1,
26:	        wordList);
-
57:	    }
58:	  };
59:	  private ArrayAdapter<String> adapter;
60:	  private List<String> wordList;
61:	
-
58:	  };
59:	  private ArrayAdapter<String> adapter;
60:	  private List<String> wordList;
61:	
62:	  public void onClick(View view) {

Read More

1:	
2:		// Logcat tag
3:		private static final String LOG = "DatabaseHelper";
4:	
5:		// Database Version
-
7:	
8:		// Database Name
9:		private static final String DATABASE_NAME = "contactsManager";
10:	
11:		// Table Names
-
10:	
11:		// Table Names
12:		private static final String TABLE_TODO = "todos";
13:		private static final String TABLE_TAG = "tags";
14:		private static final String TABLE_TODO_TAG = "todo_tags";
-
11:		// Table Names
12:		private static final String TABLE_TODO = "todos";
13:		private static final String TABLE_TAG = "tags";
14:		private static final String TABLE_TODO_TAG = "todo_tags";
15:	
-
12:		private static final String TABLE_TODO = "todos";
13:		private static final String TABLE_TAG = "tags";
14:		private static final String TABLE_TODO_TAG = "todo_tags";
15:	
16:		// Common column names
-
15:	
16:		// Common column names
17:		private static final String KEY_ID = "id";
18:		private static final String KEY_CREATED_AT = "created_at";
19:	
-
16:		// Common column names
17:		private static final String KEY_ID = "id";
18:		private static final String KEY_CREATED_AT = "created_at";
19:	
20:		// NOTES Table - column nmaes
-
19:	
20:		// NOTES Table - column nmaes
21:		private static final String KEY_TODO = "todo";
22:		private static final String KEY_STATUS = "status";
23:	
-
20:		// NOTES Table - column nmaes
21:		private static final String KEY_TODO = "todo";
22:		private static final String KEY_STATUS = "status";
23:	
24:		// TAGS Table - column names
-
23:	
24:		// TAGS Table - column names
25:		private static final String KEY_TAG_NAME = "tag_name";
26:	
27:		// NOTE_TAGS Table - column names
-
26:	
27:		// NOTE_TAGS Table - column names
28:		private static final String KEY_TODO_ID = "todo_id";
29:		private static final String KEY_TAG_ID = "tag_id";
30:	
-
27:		// NOTE_TAGS Table - column names
28:		private static final String KEY_TODO_ID = "todo_id";
29:		private static final String KEY_TAG_ID = "tag_id";
30:	
31:		// Table Create Statements
-
31:		// Table Create Statements
32:		// Todo table create statement
33:		private static final String CREATE_TABLE_TODO = "CREATE TABLE "
34:				+ TABLE_TODO + "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_TODO
35:				+ " TEXT," + KEY_STATUS + " INTEGER," + KEY_CREATED_AT
-
37:	
38:		// Tag table create statement
39:		private static final String CREATE_TABLE_TAG = "CREATE TABLE " + TABLE_TAG
40:				+ "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_TAG_NAME + " TEXT,"
41:				+ KEY_CREATED_AT + " DATETIME" + ")";
-
42:	
43:		// todo_tag table create statement
44:		private static final String CREATE_TABLE_TODO_TAG = "CREATE TABLE "
45:				+ TABLE_TODO_TAG + "(" + KEY_ID + " INTEGER PRIMARY KEY,"
46:				+ KEY_TODO_ID + " INTEGER," + KEY_TAG_ID + " INTEGER,"

Read More

6:		
7:		// give your server registration url here
8:	    static final String SERVER_URL = "http://10.0.2.2/gcm_server_php/register.php"; 
9:	
10:	    // Google project id
-
9:	
10:	    // Google project id
11:	    static final String SENDER_ID = "903913289319"; 
12:	
13:	    /**
-
14:	     * Tag used on log messages.
15:	     */
16:	    static final String TAG = "AndroidHive GCM";
17:	
18:	    static final String DISPLAY_MESSAGE_ACTION =
-
16:	    static final String TAG = "AndroidHive GCM";
17:	
18:	    static final String DISPLAY_MESSAGE_ACTION =
19:	            "com.androidhive.pushnotifications.DISPLAY_MESSAGE";
20:	
-
19:	            "com.androidhive.pushnotifications.DISPLAY_MESSAGE";
20:	
21:	    static final String EXTRA_MESSAGE = "message";
22:	
23:	    /**
-
30:	     * @param message message to be displayed.
31:	     */
32:	    static void displayMessage(Context context, String message) {
33:	        Intent intent = new Intent(DISPLAY_MESSAGE_ACTION);
34:	        intent.putExtra(EXTRA_MESSAGE, message);

Read More

3:	
4:		// URL to get contacts JSON
5:		private static String url = "http://api.androidhive.info/contacts/";
6:	
7:		// JSON Node names
-
6:	
7:		// JSON Node names
8:		private static final String TAG_CONTACTS = "contacts";
9:		private static final String TAG_ID = "id";
10:		private static final String TAG_NAME = "name";
-
7:		// JSON Node names
8:		private static final String TAG_CONTACTS = "contacts";
9:		private static final String TAG_ID = "id";
10:		private static final String TAG_NAME = "name";
11:		private static final String TAG_EMAIL = "email";
-
8:		private static final String TAG_CONTACTS = "contacts";
9:		private static final String TAG_ID = "id";
10:		private static final String TAG_NAME = "name";
11:		private static final String TAG_EMAIL = "email";
12:		private static final String TAG_ADDRESS = "address";
-
9:		private static final String TAG_ID = "id";
10:		private static final String TAG_NAME = "name";
11:		private static final String TAG_EMAIL = "email";
12:		private static final String TAG_ADDRESS = "address";
13:		private static final String TAG_GENDER = "gender";
-
10:		private static final String TAG_NAME = "name";
11:		private static final String TAG_EMAIL = "email";
12:		private static final String TAG_ADDRESS = "address";
13:		private static final String TAG_GENDER = "gender";
14:		private static final String TAG_PHONE = "phone";
-
11:		private static final String TAG_EMAIL = "email";
12:		private static final String TAG_ADDRESS = "address";
13:		private static final String TAG_GENDER = "gender";
14:		private static final String TAG_PHONE = "phone";
15:		private static final String TAG_PHONE_MOBILE = "mobile";
-
12:		private static final String TAG_ADDRESS = "address";
13:		private static final String TAG_GENDER = "gender";
14:		private static final String TAG_PHONE = "phone";
15:		private static final String TAG_PHONE_MOBILE = "mobile";
16:		private static final String TAG_PHONE_HOME = "home";
-
13:		private static final String TAG_GENDER = "gender";
14:		private static final String TAG_PHONE = "phone";
15:		private static final String TAG_PHONE_MOBILE = "mobile";
16:		private static final String TAG_PHONE_HOME = "home";
17:		private static final String TAG_PHONE_OFFICE = "office";
-
14:		private static final String TAG_PHONE = "phone";
15:		private static final String TAG_PHONE_MOBILE = "mobile";
16:		private static final String TAG_PHONE_HOME = "home";
17:		private static final String TAG_PHONE_OFFICE = "office";
18:	
-
15:		private static final String TAG_PHONE_MOBILE = "mobile";
16:		private static final String TAG_PHONE_HOME = "home";
17:		private static final String TAG_PHONE_OFFICE = "office";
18:	
19:		// contacts JSONArray

Read More

1:	@MediumTest
2:	public void testClickMeButton_clickButtonAndExpectInfoText() {
3:	    String expectedInfoText = mClickFunActivity.getString(R.string.info_text);
4:	    TouchUtils.clickView(this, mClickMeButton);
5:	    assertTrue(View.VISIBLE == mInfoTextView.getVisibility());

Read More

2:	AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
3:	// Get the string array
4:	String[] countries = getResources().getStringArray(R.array.countries_array);
5:	// Create the adapter and set it to the AutoCompleteTextView 
6:	ArrayAdapter<String> adapter = 
-
4:	String[] countries = getResources().getStringArray(R.array.countries_array);
5:	// Create the adapter and set it to the AutoCompleteTextView 
6:	ArrayAdapter<String> adapter = 
7:	        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries);
8:	textView.setAdapter(adapter);
-
5:	// Create the adapter and set it to the AutoCompleteTextView 
6:	ArrayAdapter<String> adapter = 
7:	        new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries);
8:	textView.setAdapter(adapter);
9:

Read More

11:	    assertTrue(isFinishCalled());
12:	
13:	    final String payload =
14:	            launchIntent.getStringExtra(NextActivity.EXTRAS_PAYLOAD_KEY);
15:	    assertEquals("Payload is empty", LaunchActivity.STRING_PAYLOAD, payload);

Read More

See Code Examples for Java 8 String Methods: