🌐
W3Schools
w3schools.com › java › java_ref_string.asp
Java String Methods
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
April 21, 2026 - The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method. String conversions are implemented through the ...
Discussions

Returning String Methods in Java? - Stack Overflow
I'm in a beginning programming class, and a lot of this had made sense to me up until this point, where we've started working with methods and I'm not entirely sure I understand the "static," "void... More on stackoverflow.com
🌐 stackoverflow.com
Java String Methods - You Need To Know

First method of the article is charAt... Great start! Then you realise this is probably every method available order alphabetically... This could be reduce to a "5 methods to know" to be really interesting.

More on reddit.com
🌐 r/programming
1
0
October 6, 2018
ELI5:What is a "String" in Java/programming and why is it known as a "complex added type" and other variable are known as "primitive" ?
In simplest terms, a String is an collection (referred to in programming as an "array") of characters. If you wanted to have a String that said "Reddit", it would literally be an array of character values ['R', 'e', 'd', 'd', 'i', 't']. The most fundamental difference between strings and primitive types such as "int" are that primitives are single values. Strings are collections of values (specifically, a collection of characters.) Characters themselves are primitive types. In addition, primitive types are pieces of data. Strings are objects, which are instances of classes. As far as classes go...basically, the people who made Java built a lot of code so Strings could be easy to use by programmers. (This is also why "String" is capitalized: the name of the class has a capital S.) Sorry if this is too technical...but it should answer your questions. More on reddit.com
🌐 r/explainlikeimfive
5
1
November 21, 2015
New Methods on Java Strings With JDK 11

Looks like they're taking the awful PHP "real_escape_string" approach to API development of finding increasingly strained synonyms when something needs to be fixed by making the Unicode-aware version of String.trim() be named String.strip() instead of just adding an overload for trim() that takes an option parameter to specify the trimming type.

A hypothetical alternative of trim(StringTrimOptions options), used as in these examples:

// First two are equivalent, and use the backward-compatible
// pre-existing trimming logic
str.trim();
str.trim(StringTrimOptions.ASCII_WHITESPACE);

// This example uses new Unicode-compatible trimming logic.
str.trim(StringTrimOptions.UNICODE_WHITESPACE);

... would be a much better solution that wouldn't require every developer going forward, in perpetuity, to have to discover what the non-obvious difference between trim() and strip() is (whereas the hypothetical StringTrimOptions alternative is self-explanatory to a large extent); and is forward-compatible should the need ever arise in the future for yet another type of string trimming.

(And with the isBlank() method being added too, which could probably also benefit from being able to specify the type of whitespace; maybe instead of StringSplitOptions the argument should be WhitespaceType instead so an overload ofisBlank() could read correctly with it too.)

More on reddit.com
🌐 r/programming
16
30
May 3, 2018
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-string-methods
Java String Methods - GeeksforGeeks
Java String methods are built-in functions provided by the String class to perform various operations on strings. These methods help in manipulating, comparing, searching, and formatting text efficiently.
Published   May 30, 2026
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-strings
Java – String Class and Methods with examples
int codePointAt(int index):It is similar to the charAt method however it returns the Unicode code point value of specified index rather than the character itself. I have shared several tutorials on the String in java.
🌐
Medium
beknazarsuranchiyev.medium.com › string-class-and-its-methods-in-java-147b7aedc3a9
String class and its methods in Java | by Beknazar | Medium
June 15, 2022 - String class and its methods in Java java.lang.String is the most used class in Java. It’s important to understand and be able to manipulate strings fluently. String Class String Methods Comparing …
🌐
Programiz
programiz.com › java-programming › library › string
Java String Methods | Programiz
Java has a lot of String methods that allow us to work with strings. In this reference page, you will find all the string methods available in Java.
🌐
DEV Community
dev.to › pankaj_singhr › 10-most-useful-string-methods-in-java-4lag
🎯 10 most useful string methods in Java - DEV Community
January 19, 2022 - 1 - indexOf() used to find characters and substrings in a string. It returns the index of first occurrence from left of the passed string or character syntax - public int indexOf​(String str, int fromIndex) str - substring to be search fromIndex - search begin from this index
Find elsewhere
🌐
Medium
medium.com › geekculture › all-about-string-in-java-51ba9e46181a
All About String in Java. Java Strings are objects that are… | by sajith dilshan | Geek Culture | Medium
February 8, 2023 - Java String class methods. ... A new tech publication by Start it up (https://medium.com/swlh). ... Java Strings are objects that are backed by a char array and are immutable. The class java.lang.String is used to create a string object. ... A string literal is created by using double quotes. For example: ... Each time you create a string literal, the JVM checks the string pool first. If the string already exists in the pool, a reference to the pooled instance is returned.
🌐
Codecademy
codecademy.com › learn › spring-apis-java-ii › modules › learn-java-string-methods › cheatsheet
Java II: String Methods Cheatsheet | Codecademy
This method returns a String representing the text of the combined strings. ... In Java, the equals() string method tests for equality between two Strings.
🌐
Tutorialspoint
tutorialspoint.com › java › java_strings.htm
Java - String Class
Note − The String class is immutable, so that once it is created a String object cannot be changed. If there is a necessity to make a lot of modifications to Strings of characters, then you should use String Buffer & String Builder Classes. Methods used to obtain information about an object are known as accessor methods.
🌐
W3Schools
w3schools.com › java › java_strings.asp
Java Strings
A String in Java is actually an object, which means it contains methods that can perform certain operations on strings.
🌐
Medium
medium.com › @salvipriya97 › commonly-used-string-functions-in-java-343543b06132
Commonly used String functions in Java | by Priya Salvi | Medium
January 3, 2024 - The String class in Java is part of the java.lang package and represents a sequence of characters. Strings in Java are immutable, meaning their values cannot be changed once they are created. The String class provides various methods for manipulating and extracting information from strings.
🌐
Crio
crio.do › blog › string-methods-in-java
10 Important String Methods In Java You Must Know
October 20, 2022 - Useful and important methods in Java. indexOf, toCharArray, charAt, concat, replace, substring, split, compareTo, strip, valueOf
🌐
Sanfoundry
sanfoundry.com › java-program-create-strings-use-some-important-methods-string-class
String Class Methods in Java with Examples - Sanfoundry
March 13, 2023 - 6. A new String variable “str5” is created with the value “AbCdEfGhIjKlMnOpQrStUvWxYz“, and the program uses the “split()” method on “str5” to split it into two Strings at the letter “M“. 7. The resulting Strings are assigned to an array of Strings named “str6“. The program assigns the first String in the “str6” array to a String variable named “part1” and the second String to a String variable named “part2“, which are printed with a space in between them. ... $ javac Important_Methods.java $ java Important_Methods The length of the String str1 using length() is 5 The string after concatenation using concat() is HellofromJAVA The character atindex 5 using charAt() is f The string after spliting using split() will be = AbCdEfGhIjKl and nOpQrStUvWxYz
🌐
Scaler
scaler.com › home › topics › java › strings in java
String in Java (With Examples) - Scaler Topics
June 21, 2022 - Now we are going to see some more examples of string in Java. In the above-given examples, val1 is created using the string literal, val2 is created using the new keyword and val3 is created by concatenating/joining val1 and val2. The length() method of string in Java is used to get the length of the string.
Top answer
1 of 3
4

You're correct that your issues are rooted in not understanding static. There are many resources on this, but suffice to say here that something static belongs to a Class whereas something that isn't static belogns to a specific instance. That means that

public class A{
    public static int b;

    public int x;
    public int doStuff(){
        return x;
    }

    public static void main(String[] args){
        System.out.println(b); //Valid. Who's b? A (the class we are in)'s b.
        System.out.println(x); //Error. Who's x? no instance provided, so we don't know.
        doStuff(); //Error. Who are we calling doStuff() on? Which instance?

        A a = new A();
        System.out.println(a.x); //Valid. Who's x? a (an instance of A)'s x.
    }
}

So related to that your method histogram isn't static, so you need an instance to call it. You shouldn't need an instance though; just make the method static:

Change public String histogram(int randomNum) to public static String histogram(int randomNum).

With that done, the line histogram(randomNum); becomes valid. However, you'll still get an error on System.out.print(histogram + "\n");, because histogram as defined here is a function, not a variable. This is related to the return statement. When something says return x (for any value of x), it is saying to terminate the current method call and yield the value x to whoever called the method.

For example, consider the expression 2 + 3. If you were to say int x = 2 + 3, you would expect x to have value 5 afterwards. Now consider a method:

public static int plus(int a, int b){
    return a + b;
}

And the statement: int x = plus(2, 3);. Same here, we would expect x to have value 5 afterwards. The computation is done, and whoever is waiting on that value (of type int) receives and uses the value however a single value of that type would be used in place of it. For example:

int x = plus(plus(1,2),plus(3,plus(4,1)); -> x has value 11.

Back to your example: you need to assign a variable to the String value returned from histogram(randomNum);, as such:

Change histogram(randomNum) to String s = histogram(randomNum).

This will make it all compile, but you'll hit one final roadblock: The thing won't run! This is because a runnable main method needs to be static. So change your main method to have the signature:

public static void main(String[] args){...}

Then hit the green button!

2 of 3
2

For starters your main method should be static:

public static void main(String[] Args)

Instance methods can not be called without an instance of the class they belong to where static methods can be called without an instance. So if you want to call your other methods inside the main method they must also be static unless you create an object of type prog310t then use the object to call the methods example:

public static void main(String[] Args)
{
     prog310t test = new prog310t();
     test.histogram(1);
}

But in your case you probably want to do:

public static String histogram (int randomNum)

public static void main(String[] Args)
{
     histogram(1);
}

Also you are not catching the return of histogram() method in your main method you should do like this:

  System.out.print(histogram(randomNum) + "\n");

Or

String test = histogram(randomNum);
System.out.print(test + "\n");

Static methods are part of a class and can be called without an instance but instance methods can only be called from an instance example:

public class Test
{
    public static void main(String[] args)
    {
        getNothingStatic();// this is ok
        getNothing(); // THIS IS NOT OK IT WON'T WORK NEEDS AN INSTANCE
        Test test = new Test();
        test.getNothing(); // this is ok
        getString(); // this is ok but you are not capturing the return value
        String myString = getString(); // now the return string is stored in myString for later use
    }
    public void getNothing()
    {
    }
    public static void getNothingStatic()
    {
    }
    public static String getString()
    {
        return "hello";
    }
}

Void means the method is not returning anything it is just doing some processing. You can return primitive or Object types in place of void but in your method you must specify a return if you don't use void.

🌐
Coderanch
coderanch.com › t › 729681 › java › String-Method
String Method (Beginning Java forum at Coderanch)
April 26, 2020 - Everytime you call methods that "modift" String content, the program actually creates a new object and assigns it to the object you are trying to modify. String builder is a faster alternative when you need to create String objects by appending characters one by one since it doesn't create a new object everytime. But if you say you can't use StringBuilder I suggest you this approach:
🌐
Great Learning
mygreatlearning.com › blog › it/software development › string methods java: a guide to java strings with examples
String Methods Java: A Guide To Java Strings With Examples
October 24, 2024 - static String valueOf(int value)- It is an overloaded method to convert the given type into a string. Let us check some examples of string functions in Java.
🌐
ScholarHat
scholarhat.com › home
What is String in Java - Java String Methods & Type (Examples)
Strings are immutable, meaning once created, their values cannot be changed. Java provides powerful built-in methods for string manipulation, such as concatenation, comparison, substring extraction, and pattern matching.
Published   August 30, 2025
🌐
Cogentuniversity
cogentuniversity.com › post › methods-of-strings-class-in-java
Methods of Strings Class in Java
Methods in Java are functions that perform specific tasks. The String class, being an integral part of Java, boasts a plethora of methods tailored to handle strings efficiently. These methods enable developers to manipulate strings, extract information, and transform data according to their programming needs.